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

4 vues (au cours des 30 derniers jours)
mattvanviore
mattvanviore le 1 Avr 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.

Réponses (1)

Agnish Dutta
Agnish Dutta le 10 Avr 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:

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by