필터 지우기
필터 지우기

Shaded error area of Std Dev.

조회 수: 6 (최근 30일)
Samy Alkhayat
Samy Alkhayat 2023년 3월 8일
댓글: Star Strider 2023년 3월 8일
Hello Community,
I am trying to shade the area between 2 traces of mean+Std and mean-Std with the mean passes in between. I am using:
x = CAD;
mean_y = Pav;
std_y = std(P_all,0,2);
y1 = mean_y;
y2 = mean_y - std_y;
y3 = mean_y + std_y;
figure(1)
plot(x, y1)
hold on
plot(x, y2)
hold on
plot(x, y3)
patch([x fliplr(x)], [y1 fliplr(y2)], 'g')
patch([x fliplr(x)], [y2 fliplr(y3)], 'g')
hold off
However, I get the whole area shaded under the trace due to a horizontal line that appears when excuting
patch([x fliplr(x)], [y1 fliplr(y2)], 'g')
patch([x fliplr(x)], [y2 fliplr(y3)], 'g')
Please advise if there is a better approach

채택된 답변

Star Strider
Star Strider 2023년 3월 8일
편집: Star Strider 2023년 3월 8일
It would of course help to have your data.
However this call:
std_y = std(P_all,0,2);
implies to me that your data are column vectors, not row vectors.
If that is correct, then this would be more appropriate:
patch([x; flip(x)], [y1; flip(y2)], 'g')
patch([x; flip(x)], [y2; flip(y3)], 'g')
It is the same essential idea, simply recognising the orientation of the data.
The,flip works regardless of the orientation, while fliplr simply filps the column vectors in this instance (although is appropriate if that is what you want to do).
EDIT — (8 Mar 2023 at 2:28)
With the supplied data (they are column data) —
LD = load(websave('Mathworks','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1317410/Mathworks.mat'))
LD = struct with fields:
CAD: [1440×1 double] P_all: [1440×344 double] Pav: [1440×1 double]
CAD = LD.CAD;
P_all = LD.P_all;
Pav = LD.Pav;
x = (-360:0.5:359.5)';
mean_y = Pav;
std_y = std(P_all,0,2);
y1 = mean_y;
y2 = mean_y - std_y;
y3 = mean_y + std_y;
figure
plot(x,y1)
hold on
patch([x; flip(x)], [y1; flip(y2)], 'g')
patch([x; flip(x)], [y2; flip(y3)], 'g')
hold off
xlabel('CAD')
figure
plot(x,y1)
hold on
patch([x; flip(x)], [y1; flip(y2)], 'g')
patch([x; flip(x)], [y2; flip(y3)], 'g')
hold off
xlabel('CAD')
ylim([50 80])
title('Zoom to show detail')
The standad deviation is quite small, so the lower (optional) plot zooms in to show the details.
.
  댓글 수: 4
Samy Alkhayat
Samy Alkhayat 2023년 3월 8일
It does, was not visible though due to the small Std Dev.
Thank you!
Star Strider
Star Strider 2023년 3월 8일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by