# How to shade area between standard deviations in a plot?

12 visualizaciones (últimos 30 días)
Tomaszzz el 28 de Mzo. de 2022
Editada: MANDRAKE el 18 de Ag. de 2022
Hi all,
I would like to shade the area between standard deviations.
The data is attached. My code is as follows:
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
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Jan el 28 de Mzo. de 2022
Editada: Jan el 18 de Ag. de 2022
m = data1.mean;
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 comentariosMostrar NingunoOcultar Ninguno
MANDRAKE el 18 de Ag. de 2022
Editada: MANDRAKE el 18 de Ag. de 2022
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 el 18 de Ag. de 2022
@MANDRAKE: Thanks for this comment. I've inserted some code to ensure, that the data are column vectors.

Iniciar sesión para comentar.

### Categorías

Más información sobre Annotations en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by