using histogram in a loop with hold on and off
6 views (last 30 days)
Show older comments
I am tyring to understand the use of the histogram in the following way.
I have a matrix of size (M x N). Each column represents a curve.
I calculate a mean for all the curves using mean_matrix = mean(matrix,2)
Plotting mean_matrix shows that the mean is as expected.
Next I subtract each curve from the mean value giving me a difference matrix Diff(M x N)
I then use histogram to plot Diff(M x N) so it is > hist(Diff, # of bins)
This give me a histogram with different colours, I think the different colours
are for each column of the Diff matrix ? I then took a look at using
a loop so I did >for i=1,index; hist(Diff(:,i),# of bins);end; and this
gave me a different looking graph; next I included hold on and again
I got a completely looking curve. Can someone help me understand what I did?
I would like to do is to look at the histogram curves in a 3D plot
and see the variation better.
0 Comments
Answers (2)
Michael Haderlein
on 24 Jul 2014
I try to understand and to explain. Let's take a matrix, maybe the peaks-matrix (49x49 by default) and reshape it:
matrix=peaks; %49x49
matrix2=reshape(matrix,numel(matrix)/7,7); %343x7
hist(matrix2) %histogram with 7 bars each bin, one for each column of the matrix
figure, axes, hold all
for cnt=1:7
hist(matrix2(:,cnt))
end %7 histograms stacked upon each other -> difficult to see anything
h3=histc(matrix2,linspace(minv,maxv,21),1); %calculate a histogram for each column
bar3(h3) %plot the histogram for each column
Hope that helped,
best regards,
Michael
Michael Haderlein
on 25 Jul 2014
I see I forgot to post also the line where minv,maxv is created:
minv=min(matrix2(:));maxv=max(matrix2(:));
What happens, if you execute the above written just using your Diff matrix instead of my matrix2?
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!