In Matlab, how can I save a histogram from the command line?

I have a large number of files that I need to create histograms, so I want to save them from the command line. For sites, I usually save them in Matlab using the following command:

figure = plot (x,y) saveas(figure, output, 'jpg') 

I want to do the same for histograms:

 figure = hist(x) saveas(figure, output, 'jpg') 

However, I get an error message that specifies an invalid handle. I also tried the imwrite function, the code executes but retains a clear black image. Is there any way to save my histograms?

+7
source share
3 answers

When you use hist with an output argument, it returns a counter for each bin, not a descriptor object, such as the other types of charts you use to.

Instead, take a shape descriptor, use hist without outputting arguments to plot on the shape, then save the shape.

 fh = figure; hist(x); saveas(fh, output, 'jpg') close(fh) 
+13
source

export_fig from MATLAB file sharing automatically handles this for you and has other nice features. An example of how to use it, see my other answer here .

+1
source
 fh = figure; imhist(x); saveas(fh, 'output', 'jpg'); 
0
source

All Articles