计算和绘制方差和期望值

时间:2013-07-04 09:11:40

标签: matlab

我正在获得直方图。我想计算给定直方图的标准偏差和期望值。哪个matlab函数会帮我做到这一点?其次,我想在直方图上显示方差和期望值,如下图所示。如何在这个直方图上嵌入这些线?

我的直方图用v / s表示值概率......

enter image description here

这是我的代码绘制直方图:

   edges = unique(columnB)



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

  c_elements =(n_elements)

  figure(2)
  bar(edges,c_elements,'BarWidth',4)

1 个答案:

答案 0 :(得分:3)

用于评估mean和std的值:

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

将其添加到你的情节中:

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

将为std

的平均线和红线提供绿线