I have a small script that imports a matrix from a text file, visualizes it and saves it in jpg. My matrix has a 2: 1 aspect ratio, and the image file, apparently by default, compresses to 1: 1. How to keep the original proportions of the matrix? Is it possible to use the truesize function truesize ?

 files = dir('*.txt'); for i=1:length(files) importdata(files(i).name); h = imagesc(ans); set(gca,'CLim',[-0.3395 8.3216]); colorbar; saveas(h,[files(i).name '.jpg'], 'jpg'); end 

    1 answer 1

    use either axis equal or axis image before saveas. Another option is to manually make an image through gray2ind and write using imwrite