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;
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With