How to shade area between standard deviations in a plot?

조회 수: 34 (최근 30일)
Tomaszzz
Tomaszzz 2022년 3월 28일
편집: MANDRAKE 2022년 8월 18일
Hi all,
I would like to shade the area between standard deviations.
The data is attached. My code is as follows:
load 'mean'
load 'std';
bottom_sd=(mean-sd);
top_sd=(mean+sd);
figure(1)
plot(mean,(bottom_sd),'r');
hold on;
plot(mean,(top_sd),'r');
patch([mean(:); flipud(mean(:))], [mean(:)-sd(:); flipud(mean(:)+sd(:))], [0.6 0.7 0.8])
hold off
But it gives me this. Cold you please help?

채택된 답변

Jan
Jan 2022년 3월 28일
편집: Jan 2022년 8월 18일
data1 = load('mean.mat');
m = data1.mean;
data2 = loadt('std.mat');
s = data2.sd; % Do not use "mean" and "std" as variables!
x = (1:numel(m)).';
m = m(:); % [EDITED] Be sure that the data are column vectors
s = s(:); % [EDITED]
figure;
axes('NextPlot', 'add'); % as: hold on
size(x)
size(low)
patch([x; flip(x)], [m + s; flip(m - s)], [0.6 0.7 0.8])
plot(x, m);
Your code mixes x and y coordinates.
  댓글 수: 2
MANDRAKE
MANDRAKE 2022년 8월 18일
편집: MANDRAKE 2022년 8월 18일
Thanks a lot Jan.
The line with the patch function should be something like
patch([x; flip(x)], [m + s, flip(m - s)], [0.6 0.7 0.8])
to avoid the possible error about having two vectors of different lengths.
Jan
Jan 2022년 8월 18일
@MANDRAKE: Thanks for this comment. I've inserted some code to ensure, that the data are column vectors.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by