Hi,
Here is my code for my work and my data is already set up in columns on excel. The problem I'm getting is that my standard devation corridors are not filling up with the desired colors for both plots. Why might that be so? Attached is my code and the result of it. Thanks for your help in advance.
k
%Variance Corridor:
dataset=xlsread('Book1.xlsx', 'Sheet1')
tensile_stress = dataset(:,1); % your mean stress;
tensile_strain = dataset(:,2); % your mean strain;
std_dev_tensile_stress = dataset(:,3); % your std of stress;
surrogate_stress=dataset(:,4); % mean surrogate stress
surrogate_strain=dataset(:,5); % mean surrogate strain
std_dev_surrogate_stress=dataset(:,6); % surrogate std
x = tensile_strain;
y = tensile_stress;
sd = std_dev_tensile_stress;
x1=surrogate_strain
y1=surrogate_stress
sd1=std_dev_surrogate_stress
figure
patch([x; flipud(x)], [y-sd; flipud(y+sd)], [1,1,0]);
hold on
plot(x,y);
hold on
patch([x1; flipud(x1)], [y1-sd1; flipud(y1+sd1)], [0,1,1]);
hold on
plot(x1,y1);
hold off

 채택된 답변

Star Strider
Star Strider 2021년 9월 19일

1 개 추천

There are NaN values in ‘x’, ‘y’, and ‘sd’. This ia frequent cause of patch failures. Remove them and it works!
Try this —
%Variance Corridor:
dataset=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/743199/Book1.xlsx', 'Sheet',1)
dataset = 27×6
0 0 0 0 0 0 0.6709 0.0040 0.2540 0.5871 0.0060 0.4861 1.4690 0.0109 1.1858 1.4076 0.0158 1.1510 2.6156 0.0224 1.9156 2.2079 0.0243 1.8720 4.0214 0.0368 2.8618 2.8439 0.0340 2.3422 5.5936 0.0527 3.9622 3.2271 0.0477 2.4442 7.2949 0.0697 5.2204 3.3831 0.0644 2.2528 9.1129 0.0860 6.5480 3.3916 0.0835 2.0559 11.0479 0.0994 7.9833 3.3819 0.1048 2.1513 11.8582 0.1055 7.5384 3.4900 0.1274 2.5223
tensile_stress = dataset(:,1); % your mean stress;
tensile_strain = dataset(:,2); % your mean strain;
std_dev_tensile_stress = dataset(:,3); % your std of stress;
surrogate_stress=dataset(:,4); % mean surrogate stress
surrogate_strain=dataset(:,5); % mean surrogate strain
std_dev_surrogate_stress=dataset(:,6); % surrogate std
x = tensile_strain
x = 27×1
0 0.0040 0.0109 0.0224 0.0368 0.0527 0.0697 0.0860 0.0994 0.1055
y = tensile_stress
y = 27×1
0 0.6709 1.4690 2.6156 4.0214 5.5936 7.2949 9.1129 11.0479 11.8582
sd = std_dev_tensile_stress
sd = 27×1
0 0.2540 1.1858 1.9156 2.8618 3.9622 5.2204 6.5480 7.9833 7.5384
x1=surrogate_strain
x1 = 27×1
0 0.0060 0.0158 0.0243 0.0340 0.0477 0.0644 0.0835 0.1048 0.1274
y1=surrogate_stress
y1 = 27×1
0 0.5871 1.4076 2.2079 2.8439 3.2271 3.3831 3.3916 3.3819 3.4900
sd1=std_dev_surrogate_stress
sd1 = 27×1
0 0.4861 1.1510 1.8720 2.3422 2.4442 2.2528 2.0559 2.1513 2.5223
x = rmmissing(x)
x = 24×1
0 0.0040 0.0109 0.0224 0.0368 0.0527 0.0697 0.0860 0.0994 0.1055
y = rmmissing(y)
y = 24×1
0 0.6709 1.4690 2.6156 4.0214 5.5936 7.2949 9.1129 11.0479 11.8582
sd = rmmissing(sd)
sd = 24×1
0 0.2540 1.1858 1.9156 2.8618 3.9622 5.2204 6.5480 7.9833 7.5384
y-sd
ans = 24×1
0 0.4169 0.2832 0.7000 1.1597 1.6313 2.0744 2.5649 3.0646 4.3197
y+sd
ans = 24×1
0 0.9249 2.6548 4.5312 6.8832 9.5558 12.5153 15.6608 19.0312 19.3966
figure
patch([x; flipud(x)], [y-sd; flipud(y+sd)], [1,1,0], 'FaceAlpha',0.5);
hold on
plot(x,y);
patch([x1; flipud(x1)], [y1-sd1; flipud(y1+sd1)], [0,1,1], 'FaceAlpha',0.5);
plot(x1,y1);
hold off
.

댓글 수: 3

Kev
Kev 2021년 9월 19일
Thank you all. It works!
Star Strider
Star Strider 2021년 9월 19일
My pleasure!
.
Image Analyst
Image Analyst 2021년 9월 19일
편집: Image Analyst 2021년 9월 19일
@Kev then please "Accept this answer" to award Star or Cyclist (you can only Accept one, though you can vote for any/all of the Answers) his reputation points and let others know it's been solved. Thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

the cyclist
the cyclist 2021년 9월 19일

1 개 추천

It's because the last three values of x and y are NaN.
dataset=xlsread('Book1.xlsx', 'Sheet1');
tensile_stress = dataset(:,1); % your mean stress;
tensile_strain = dataset(:,2); % your mean strain;
std_dev_tensile_stress = dataset(:,3); % your std of stress;
surrogate_stress=dataset(:,4); % mean surrogate stress
surrogate_strain=dataset(:,5); % mean surrogate strain
std_dev_surrogate_stress=dataset(:,6); % surrogate std
x = tensile_strain;
y = tensile_stress;
sd = std_dev_tensile_stress;
x1 = surrogate_strain;
y1 = surrogate_stress;
sd1 = std_dev_surrogate_stress;
figure
hold on
patch([x(1:24); flipud(x(1:24))], [y(1:24)-sd(1:24); flipud(y(1:24)+sd(1:24))], [1,1,0]);
plot(x,y);
patch([x1; flipud(x1)], [y1-sd1; flipud(y1+sd1)], [0,1,1]);
plot(x1,y1);
hold off
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 9월 19일
편집: Sulaymon Eshkabilov 2021년 9월 19일

0 개 추천

In your data, there are some missing data points (x, y, std) which must be removed and then everything works ok. Here is the corrected part of the code:
...
figure
A = [x; flipud(x)];
B = [y-sd; flipud(y+sd)];
IDX = isnan(A);
A(IDX)=[];
B(IDX)=[];
patch(A,B, [1,1,0]);
hold on
plot(x,y);
...

카테고리

도움말 센터File Exchange에서 Stress and Strain에 대해 자세히 알아보기

질문:

Kev
2021년 9월 19일

편집:

2021년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by