Filter löschen
Filter löschen

How to do a error bar from two curves along y axis in the same plot?

2 Ansichten (letzte 30 Tage)
mattvanviore
mattvanviore am 1 Apr. 2019
Beantwortet: Agnish Dutta am 10 Apr. 2019
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.

Antworten (1)

Agnish Dutta
Agnish Dutta am 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:

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by