Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ploting multiple histogram in same figure with different color in matlab

i have a 600x24 matrix a, i want to make histogram of each column in same figure but with differnet color in MATLAB, i used the following code but it did not give me rainbow color,i used the following code, please help

col = hsv(24);

hold on;

for m = 1:24
hist(a(:,m), 50);
h = findobj(gca,'Type','patch');
set(h,'FaceColor', col(m,:),'EdgeColor',col(m,:));
alpha(0.3);
end

hold off;
like image 485
navneetcverma Avatar asked Oct 01 '12 16:10

navneetcverma


1 Answers

The MATLAB hist() function works on matrices, and processes each column of the matrix separately. The bar() function can be used to plot the histogram yourself, and color the entries appropriately. Therefore you should be able to achieve the result using

[h,x] = hist(a,50); % histogram of every column and the bins vector
bar(x,h);           % plot histograms

% create a legend
l = cell(1,24);
for n=1:24, l{n} = num2str(n), end;
legend(l);
like image 78
Phonon Avatar answered Oct 12 '22 23:10

Phonon