How to create one errorbar for multiple data points?

Hello,
i want to plot a x-vector (1,100) and a y-vector (1,100) with an errorbar. I have already calculated the single value for the standard deviation of the y-vector. This y-vector has been measured 100 times, so i just need one standard deviation for the 100 values of y.
I tried to do this with:
x = ones(1,100);
y = ...;
error = 4.17e-04;
errorbar(x,y,error,'.');

1 件のコメント

VBBV
VBBV 2021 年 2 月 3 日
error variable must be of same size as x and y see the doc page https://in.mathworks.com/help/matlab/ref/errorbar.html

サインインしてコメントする。

 採用された回答

Daniel Pollard
Daniel Pollard 2021 年 2 月 3 日

1 投票

If I understand you right, could you do something like
figure; hold on
plot(x, y, 'bx')
errorbar(mean(x), mean(y), std(y), 'k+')
hold off
which I believe should plot all of your y values at x=1, and then overlay an errorbar centred at the mean point with a size equal to the standard deviation of y.

3 件のコメント

LM
LM 2021 年 2 月 3 日
That's exactly what i was trying to do. Thanks a lot. May i ask you to explain me, why this ist working the way it is?
Daniel Pollard
Daniel Pollard 2021 年 2 月 3 日
The code I gave you does two things. It plots each data point individually, which I specified as blue x's. In your case this plots the y values on a vertical line corresponding to x=1. Then, it plots an extra point: the mean value of y, against the mean value of x. mean(x) is just 1, but I left it like that so you can reuse the code for other data. mean(y) is the averge value of all of the y values. std calculates the standard deviation of the y values.
The hold command does a lot of work here too; when you call
hold on
it says to Matlab "keep plotting these things on the same figure until I call
hold off
which I do after. Otherwise when you call errorbar, it will overwrite the previous plot.
LM
LM 2021 年 2 月 3 日
Understood. Thank you for your effort.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeErrorbars についてさらに検索

タグ

質問済み:

LM
2021 年 2 月 3 日

コメント済み:

LM
2021 年 2 月 3 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by