How can I plot Histograms for multiple data

1 view (last 30 days)
I have about 20 .mat data and I need a code to load all the data from a folder and calculate their histograms. cheers.
  1 Comment
Geoff Hayes
Geoff Hayes on 1 Dec 2014
Kemi - what have you tried so far? See load to load a mat data file, and hist to create the histogram.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Dec 2014
Inside each loop call hist() and plot(). You might want to use a different color for each plot to distinguish them from each other.
[counts, binCenters] = hist(yourData, numberOfBins);
hold on;
plot(binCenters, counts, 'Color', rand(1,3));
  2 Comments
kemi
kemi on 1 Dec 2014
Thanks very much for this solution. Could you please check for me if this code will work. I just put them together based on the FAQ I read.
k = 1:20
matFileName = sprintf('mat%d.mat', k);
matData = load(matFileName);
[counts,binCentres] = hist(matData, 100);
hold on;
plot(binCenters, counts, ' color', rand(1,3));
end
Image Analyst
Image Analyst on 1 Dec 2014
You need the word "for" before the k= line. And you will need to extract your image from matData since matData is a structure:
fieldnames(matData) % Display contents of matdata in command window
myData = matData.whateverYouCalledYourData;
[counts,binCentres] = hist(myData, 100);

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!