How to do a error bar from two curves along y axis in the same plot?
3 views (last 30 days)
Show older comments
I have two curves (x1,y1) and (x2,y2) and i want to do a error bar in the plot which marks the difference between y1 and y2. Can you write the code?
Thanks for the suggestions.
0 Comments
Answers (1)
Agnish Dutta
on 10 Apr 2019
From what I understand, you are trying to plot the curve (x1, y1) along with the deviations of the curve (x2, y2) from (x1, y1).
This could be done with the "errorbar(x,y,neg,pos)" function which draws a vertical error bar at each data point, where 'neg' determines the length below the data point and 'pos' determines the length above the data point, respectively.
The following code snippet demonstrates the use of this function, to plot sin(x) against x along with the deviation of cos(x) from sin(x).
x = linspace(-2*pi, 2*pi, 100);
f1_x = sin(x);
f2_x = cos(x);
err = f2_x - f1_x;
pos = zeros(1, length(x));
neg = zeros(1, length(x));
pos(f2_x < f1_x) = err(f2_x < f1_x);
neg(f2_x > f1_x) = err(f2_x > f1_x);
errorbar(x, f1_x, pos, neg);
For further reference, consider going through the following document:
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots 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!