Shaded Standard Deviation Corridors
10 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Star Strider
on 19 Sep 2021
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)
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
x = rmmissing(x)
y = rmmissing(y)
sd = rmmissing(sd)
y-sd
y+sd
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 Comments
Image Analyst
on 19 Sep 2021
Edited: Image Analyst
on 19 Sep 2021
@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.
More Answers (2)
the cyclist
on 19 Sep 2021
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
on 19 Sep 2021
Edited: Sulaymon Eshkabilov
on 19 Sep 2021
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);
...
0 Comments
See Also
Categories
Find more on Stress and Strain 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!