【发布时间】:2018-02-10 03:32:49
【问题描述】:
我尝试在直方图的每个条形上绘制标准差。目前,我从以下直方图开始:
为了得到这个直方图,我使用了y 数组(大小为 8x3),如下所示:
% Abscissa
x=[2 4 8 16 32 64 128 256];
% Plot histogram
figure(1);
hbar=bar(log2(x),y(1:8,1:3),'b');
现在,我想在 24 个条形图上绘制标准差。我有一个大小为 (8x3) 的数组 deviation。
我试过了:
% Abscissa
x=[2 4 8 16 32 64 128 256];
% Plot histogram
figure(1);
hbar=bar(log2(x),y(1:8,1:3),'b');
hold on;
% Plot standard deviation
errorbar(log2(x),y(1:8,1:3),deviation(1:8,1:3));
但我收到以下错误:
Error using errorbar>checkSingleInput (line 264)
XData must be the same size as YData.
Error in errorbar (line 94)
x = checkSingleInput(x, sz, 'XData');
Error in plot_benchmark (line 29)
errorbar(log2(x),y(1:8,1:3),deviation(1:8,1:3));
errorbar 似乎不支持二维数组。如果是这种情况,如何规避此问题并能够为上图中显示的 24 个直方图条中的每一个绘制误差条?
更新 1: 我试图通过这样做来调整可能重复的解决方案:
hbar=bar(log2(x),y(1:8,1:3),'b');
hold on;
% Compute x position for each bar
for i=1:8
x1=get(get(hbar(i),'children'),'xdata');
barsx(i,1:3)=mean(x1,1)
end
% Plot standard deviation
errorbar(barsx,y(1:8,1:3),deviation(1:8,1:3));
但是数组barsx 是空的。这是为什么呢?
【问题讨论】:
-
如何计算标准差?您尝试计算哪个分布之间的误差。
-
偏差数组的值是从数据文件中提取的(正好是第 4 列):% 加载输入文件 data=load('input.txt'); % 获取 i=1:3 的条形高度 y(1:8,i)=data((i-1)*8+1:i*8,3);结束 % i=1:3 的标准偏差 偏差(1:8,i)=data((i-1)*8+1:i*8,4);结束