user3610523
user3610523

Reputation: 1

How do I save histogram to file in matlab?

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?

Upvotes: 0

Views: 10674

Answers (1)

otterb
otterb

Reputation: 2710

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.

Upvotes: 1

Related Questions