How do I save histogram to file in matlab?

六月ゝ 毕业季﹏ 提交于 2020-01-06 12:59:06

问题


figure;
histogram = hist(np,180);
name=['histogram-' int2str(k) '.png'];  
%% k is the iterator so basically I want to save all the images using a loop.
imwrite(out,name);

The image I got is only a horizontal line. Does someone know how to fix this?


回答1:


you can use savefig instead of imwrite

here is the doc http://www.mathworks.ch/ch/help/matlab/ref/savefig.html

savefig(h,filename)

h is the handle of figure. you could skip h to save the current figure.

(edit) savefig may not be there depending on the MATLAB version. In 2012b, it does not exit.

So saveas may be better:

f=figure;
hist([1 2 2 3]);
saveas(f, 'histogram-1.png')

This worked in MATALB 2012b. You can save it as .fig too.



来源:https://stackoverflow.com/questions/23659044/how-do-i-save-histogram-to-file-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!