如何使用指示标准偏差的误差线绘制散点图

时间:2015-01-30 21:50:21

标签: matlab statistics regression

我有一组数据Y v / s X(~20k数据点),当绘制时是散射。我想为Y的范围绘制Y的误差条(例如,X轴的长度为100,然后我希望误差条表示每10个X单位的Y的标准偏差)

1 个答案:

答案 0 :(得分:2)

这是一个尝试:

N = 100;    % Number of points
n = 10;     % Number of x-bins

% Define and plot points
x = rand(N,1);
y = x.*rand(N,1);
scatter(x, y, '+');

% Define errorbar
bin = linspace(min(x), max(x), n+1);
ind = sum(bsxfun(@minus, x, ones(N,1)*bin)>=0,2);

m = NaN(n,1);
e = NaN(n,1);
for i = 1:n
    m(i) = mean(y(ind==i));   % Mean value over the bin
    e(i) = std(y(ind==i));    % Standard deviation
end

hold on
u = (bin(1:end-1)+bin(2:end))/2;
errorbar(u,m,e,'k');

希望这有帮助。