필터 지우기
필터 지우기

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

조회 수: 6 (최근 30일)
mattvanviore
mattvanviore 2019년 4월 1일
답변: Agnish Dutta 2019년 4월 10일
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.

답변 (1개)

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by