在matlab中绘制不同颜色的同一图中的多个直方图

nav*_*rma 6 matlab plot histogram

我有一个600x24的矩阵a,我想在相同的图中制作每列的直方图,但在MATLAB中使用不同的颜色,我使用下面的代码,但它没有给我彩虹色,我使用下面的代码,请帮助

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;
Run Code Online (Sandbox Code Playgroud)

Pho*_*non 6

MATLAB hist()函数适用于矩阵,并分别处理矩阵的每一列.该bar()功能可用于自己绘制直方图,并适当地为条目着色.因此,您应该能够使用获得的结果

[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);
Run Code Online (Sandbox Code Playgroud)