Fill area between two vertical curves
11 views (last 30 days)
Show older comments
Marcus Johnson
on 25 Mar 2024
Commented: Marcus Johnson
on 25 Mar 2024
Hello,
I have the following code:
value = [NaN NaN NaN 186.7646 198.4115 191.1406 180.8430 175.7136 ...
167.7459 151.2865 144.5964 139.8148 139.4305 188.2865 204.3296 228.8586 254.0547]; % My values
std = [NaN NaN NaN 78.2946 81.7295 83.1143 84.2082 84.5829 82.0337 83.9719 83.5152 81.8107 94.7622 ...
91.5085 81.8504 82.4451 91.2520]; % The standard deviation of the values
height = [500 1000 1500 2000 3000 4000 5000 6000 7000 ...
8000 9000 10000 11000 12000 13000 14000 15000]; % The altitudes
figure
hold on
plot(value,height,'r')
plot(value-std,height,'black')
plot(value+std,height,'black')
ylim([0 15000])
yticks([500 1000 1500 2000 2500 5000 7500 10000 12500 15000])
xlim([0 360])
xticks([0 90 180 270 360])
Is there a way to shade the area between the two black curves?
Sort of like the way it is done in these figures:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1650796/image.png)
2 Comments
Alexander
on 25 Mar 2024
Only some piece of advice, it's not a good idea to use std as variable because it's shadowing the function std().
Accepted Answer
Alan Stevens
on 25 Mar 2024
Like this:
value = [186.7646 198.4115 191.1406 180.8430 175.7136 ...
167.7459 151.2865 144.5964 139.8148 139.4305 188.2865 204.3296 228.8586 254.0547]; % My values
std = [78.2946 81.7295 83.1143 84.2082 84.5829 82.0337 83.9719 83.5152 81.8107 94.7622 ...
91.5085 81.8504 82.4451 91.2520]; % The standard deviation of the values
height = [2000 3000 4000 5000 6000 7000 ...
8000 9000 10000 11000 12000 13000 14000 15000]; % The altitudes
figure
hold on
X = [value-std, fliplr(value+std)];
Y = [height, fliplr(height)];
fill(X,Y,'g')
plot(value,height,'r')
plot(value-std,height,'black')
plot(value+std,height,'black')
ylim([0 15000])
yticks([500 1000 1500 2000 2500 5000 7500 10000 12500 15000])
xlim([0 360])
xticks([0 90 180 270 360])
More Answers (0)
See Also
Categories
Find more on Axis Labels 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!