making a plot kinda of like an errorbar plot

hi guys,
i want to make a plot that sort of looks like an error bar plot but without the mean value, just the top and bottom data points. it would be great if the errorbar plot would let me give the command errorbar(x,y_lower,y_upper,' ') but of course that doesnt work. so i was thinking about doing something like:
plot(x1, y_lower1,y_upper1,'o') and somehow connecting them with a line, and then hold on, and then plot(x2, y_lower2,y_upper2,'o') ... and then somehow looping over plot statements for all the elements in my data set? but i can't get this to work either?
would this be the right way to do it? or is there a plot type that would be easier to use? (and have me asking fewer questions about)

回答 (1 件)

Voss
Voss 2022 年 5 月 16 日

0 投票

Something like this?
x = 1:10;
y = zeros(1,10);
err = randn(1,10);
errorbar(x,y,err,'LineStyle','none')
xlim([0 11])

5 件のコメント

Adam Jurhs
Adam Jurhs 2022 年 5 月 16 日
i think so? maybe?
my data isn't actully "error data" per se, it's more like [y1lower, y1upper], [y2lower, y2upper], and then [y3lower, y3upper] ...
i don't have access to my computer right now so i'll try your answer tomorrow. hopefully it will work...
thanks! Todd
Adam Jurhs
Adam Jurhs 2022 年 5 月 17 日
編集済み: Voss 2022 年 5 月 17 日
ok, that's "mostly" right. i just haven't been able to figure out how to get errorbar plot function to work with my data. so here i'll make up some dummy data for the Y axis.
x=[1,2,3];
minVals=[5,2,3];
maxVals=[12,7,9];
diff=maxVals-minVals;
(i don't know how to make a plot in this webpage window or make my text look like MATLAB code which would probably be more helpful, but i'll describe my outcome as best i can, and i think you'll understand)
[EDIT (@_): I fixed it; use the controls at the top of the comment/answer box for formatting text and running code]
if i make the plot
subplot(3,1,1)
errorbar(x,maxVals,minVals, 'LineStyle','none')
xlim([0 4])
i get a plot with the "bottom y values" equal to 7 and 5 and 6. this is equivalent to diff. and the "top y values" equal to 17 and 9 and 12. this is equvialent to the sum of minVals and maxVals. neither of these bottom y values or top y values match minVals or maxVals so these are incorrect.
if i make the plot
subplot(3,1,2)
errorbar(x,maxVals,diff, 'LineStyle','none')
xlim([0 4])
i get a plot with the "bottom y values" equal to minVals, which is correct, but the "top y values" equal to 19 and 12 and 15. this is equvialent to the sum of maxVals and diff and is incorrect.
if i make the plot
subplot(3,1,3)
errorbar(x,minVals,diff, 'LineStyle','none')
xlim([0 4])
i get a plot with the "top y values" equal to maxVals, which is correct, but the "bottom y values" equal to -2 and -3 and -3 which i don't know what the heck that's equal to.
i have tried all the permutations of possible assignments of minVals, maxVals, and diff going into the errorbar plot and i have'nt been able to figure out the right permutation. can someone PLEASE help me?
Voss
Voss 2022 年 5 月 17 日
When using errorbar(x,y,err), y is the "center" of each bar, i.e., the value in the middle of min and max, and err is half the height of each bar.
Given just the min and max values, you have the total height of each bar, (maxVals-minVals), so the half-heights are (maxVals-minVals)/2, and the centers are (maxVals+minVals)/2, the average of min and max.
x=[1,2,3];
minVals=[5,2,3];
maxVals=[12,7,9];
% don't use diff as a variable name since it's the name of a built-in function
err=maxVals-minVals; % total height of bars
center = (maxVals+minVals)/2;
% center = minVals+err/2; % same
errorbar(x,center,err/2,'LineStyle','none')
xlim([0 4])
Or, defining err to be the half-heights:
err = (maxVals-minVals)/2; % half-height of bars
center = (maxVals+minVals)/2;
% center = minVals+err; % same
figure();
errorbar(x,center,err,'LineStyle','none')
xlim([0 4])
Voss
Voss 2022 年 5 月 17 日
@Adam Jurhs Comment posted as "Answer" moved here
awesome!!! that worked. THANKS i've been pulling my hair out all morning trying to figure this thing out - arrrgh
i need more ecxperience learning some of the non-typical plotting functions MatLab has built-in
Voss
Voss 2022 年 5 月 17 日
編集済み: Voss 2022 年 5 月 17 日
Great! You're welcome!
Please mark my answer as Accepted if you don't mind!

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

カテゴリ

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

製品

リリース

R2021b

タグ

質問済み:

2022 年 5 月 16 日

編集済み:

2022 年 5 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by