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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 1 Dez. 2014

0 Stimmen

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 Kommentare

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
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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by