How to shade area between standard deviations in a plot?
14 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Jan
on 28 Mar 2022
Edited: Jan
on 18 Aug 2022
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.
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!