在直方图上绘制线条

时间:2013-07-04 15:55:11

标签: matlab plot histogram

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

enter image description here

这是我的代码:

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

1 个答案:

答案 0 :(得分:4)

使用

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

而不是

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