【问题标题】:Plotting lines over histogram在直方图上绘制线条
【发布时间】:2013-07-04 15:55:11
【问题描述】:

我想在直方图上绘制标准差和平均值,如下所示。

这是我的代码:

         filename = 'C:\Users\unique.xlsx';
        %removed duplicate entries from the file

           columnB = xlsread(filename,'B:B');



             edges = unique(columnB)



        n_elements =histc(columnB, edges)/numel(columnB);

          bar(edges,n_elements,'BarWidth',4)

           meanB=mean(columnB)   % expectation
           stdB=std(columnB)

          figure(2)
           hold on
            ylim=get(gca,'ylim')
           line([meanB meanB], ylim,'g')
              hold on
           line ([meanB+stdB meanB+stdB NaN meanB-stdB meanB-stdB] , [ylim NaN   ylim],'r')

但它给了我以下错误:

   ??? Error using ==> line
       String argument is an unknown option.

     Error in ==> read at 23
    line([meanB meanB], ylim,'g')

【问题讨论】:

    标签: matlab plot histogram


    【解决方案1】:

    使用

    line([meanB meanB], ylim, 'Color','g');
    

    而不是

    line([meanB meanB], ylim,'g');
    

    【讨论】:

    • 谢谢你的工作,但有一个问题我想用一条水平线显示标准偏差,但我得到两条垂直线。如何实现如图所示的水平线。