Fill area between two vertical curves

조회 수: 7 (최근 30일)
Marcus Johnson
Marcus Johnson 2024년 3월 25일
댓글: Marcus Johnson 2024년 3월 25일
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