Fill area between two vertical curves

14 次查看(过去 30 天)
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:
  2 个评论
Alexander
Alexander 2024-3-25
Only some piece of advice, it's not a good idea to use std as variable because it's shadowing the function std().
Marcus Johnson
Marcus Johnson 2024-3-25
That is true, I just used the name std here to indicate that it is the standard deviation. In my actual code I have a different name.

请先登录,再进行评论。

采纳的回答

Alan Stevens
Alan Stevens 2024-3-25
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])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by