How to do a error bar from two curves along y axis in the same plot?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Agnish Dutta
2019-4-10
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!