Domanda

I am plotting some equations as figures in Matlab and then I am trying to save the figure but it screws up the saved image.

This is how the image is displayed as a matlab figure: enter image description here

However, when I try to save as an image it gets screwed up and comes out like this: enter image description here

Is there a way for me to save this properly?

I have tried the following commands and none of them work.

print(gcf,'-dbmp', 'eqn')
saveas(gcf,'eqn.bmp')

I would appreciate any help!

Thanks!

È stato utile?

Soluzione

To get a faithful reproduction of what you see on screen, you have to use the getframe and frame2im commands as follows,

F = getframe(gcf);
[im,map] = frame2im(F);
if isempty(map)
    imwrite(im,'figure.bmp');
else
    imwrite(im,map,'figure.bmp');
end

If you use saveas or print, you will likely get a file with different dimensions and objects scaled differently, which could cause equations to get drawn incorrectly. The operation of getframe ensures the file resolution reflects what you have on screen. From the documentation:

Resolution of Captured Frames

The resolution of the framed image depends on the size of the axes in pixels when getframe is called. As the getframe command takes a snapshot of the screen, if the axes is small in size (e.g.,because you have restricted the view to a window within the axes), getframe captures fewer screen pixels, ...

This means there is no redrawing at a different scale (what messes up the equation).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top