How to save scope to an image file without using plot?

后端 未结 3 1131
不知归路
不知归路 2021-01-06 08:07

This condition is very important, because plot stretches my graph in an unacceptable manner.

3条回答
  •  长发绾君心
    2021-01-06 08:25

    As the answer of gnovice is outdated (at least since R2013), and the new builtin function is rather inconvenient to use, I'd like to suggest my little script.

    set(0,'ShowHiddenHandles','On')
    set(gcf,'Units','centimeters','PaperUnits','centimeters')
    pos = get(gcf,'Position');
    set(gcf,'PaperPosition',[0 0 pos(3) pos(4)],'Papersize',[ pos(3),pos(4) ]);
    set(gcf,'InvertHardcopy','off','Renderer','painters')
    saveas(gcf,'scope.pdf')
    

    Which gives you a vector graphic in exactly the same size and look, like the last opened scope window. Of course you can modify additional properties and also print it as jpeg with a certain resolution. But then you should rather use print:

    ...
    set(gcf,'Renderer','zbuffer')
    print(gcf,'scope.jpg','-djpeg','-r600')
    

    results into a 600dpi Jpeg file. The units doesn't really matter, as long as they are consistent between figure and paper.

提交回复
热议问题