making a plot kinda of like an errorbar plot
Show older comments
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)
Answers (1)
Something like this?
x = 1:10;
y = zeros(1,10);
err = randn(1,10);
errorbar(x,y,err,'LineStyle','none')
xlim([0 11])
5 Comments
Adam Jurhs
on 16 May 2022
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
on 17 May 2022
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
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


