How can I plot Histograms for multiple data

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 件のコメント

Geoff Hayes
Geoff Hayes 2014 年 12 月 1 日
Kemi - what have you tried so far? See load to load a mat data file, and hist to create the histogram.

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2014 年 12 月 1 日

0 投票

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 件のコメント

kemi
kemi 2014 年 12 月 1 日
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 2014 年 12 月 1 日
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);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2014 年 12 月 1 日

コメント済み:

2014 年 12 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by