【问题标题】:ploting multiple histogram in same figure with different color in matlab在matlab中以不同颜色在同一图中绘制多个直方图
【发布时间】:2012-10-01 16:50:13
【问题描述】:

我有一个 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;

【问题讨论】:

    标签: matlab plot histogram


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2021-08-29
      • 2016-12-13
      • 2014-10-02
      • 1970-01-01
      相关资源
      最近更新 更多