while loop not working
Afficher commentaires plus anciens
Hello everyone!
So, I've been working on a code that will allow me to separate five cycles of stress and strain into there segement going up and then down making 10 plots. (Mechanics of materials). The code here is for the first two cycles, so four plots are attempted. My code is as follows;
%%Cycle 1 Separation
g=1;
Cycle1UpStop=1;
A=[5 5];
while (A(1,1)>-0.0001) & (AverageStrain(g,1)<0.35)
h = AverageStrain(1+g:20+g,:);
i = AverageStress(1+g:20+g,:);
A = polyfit(h,i,1);
Cycle1UpStop = g+10;
g = g+20;
end
Cycle1UpStrain=AverageStrain(1:Cycle1UpStop,1);
Cycle1UpStress=AverageStress(1:Cycle1UpStop,1);
subplot(3,3,1)
plot (Cycle1UpStrain, Cycle1UpStress);
k=100;
Cycle1DownStop=Cycle1UpStop;
while k>0.17 & k<150
Cycle1DownStop=Cycle1DownStop+1;
k=AverageStress(Cycle1DownStop,:);
end
Cycle1DownStrain=AverageStrain(Cycle1UpStop+1:Cycle1DownStop,:);
Cycle1DownStress=AverageStress(Cycle1UpStop+1:Cycle1DownStop,:);
subplot(3,3,2)
plot (Cycle1DownStrain, Cycle1DownStress);
%%Cycle 2 Separation
g2=Cycle1DownStop;
Cycle2UpStop=Cycle1DownStop;
A2=[5 5];
while (A2(1,1)>-0.0001) & (AverageStrain(g2,1)<0.35)
h2 = AverageStrain(1+g2:20+g2,:);
i2 = AverageStress(1+g2:20+g2,:);
A2 = polyfit(h2,i2,1);
Cycle2UpStop = g2+10;
g2 = g2+20;
end
Cycle2UpStrain=AverageStrain(Cycle1DownStop:Cycle2UpStop,1);
Cycle2UpStress=AverageStress(Cycle1DownStop:Cycle2UpStop,1);
subplot(3,3,3)
plot (Cycle2UpStrain, Cycle2UpStress);
k2=100;
Cycle2DownStop=Cycle2UpStop;
while k2>.17 & k2<150
Cycle2DownStop=Cycle2DownStop+1;
k2=AverageStress(Cycle2DownStop,:);
end
Cycle2DownStrain=AverageStrain(Cycle2UpStop+1:Cycle2DownStop,:);
Cycle2DownStress=AverageStress(Cycle2UpStop+1:Cycle2DownStop,:);
subplot(3,3,4)
plot (Cycle2DownStrain, Cycle2DownStress);
The problem I'm having that on the second cycle my plot for Cycle2UpStrain vs, Cycle2UpStress ends to early. See plots picture;

Note: AverageStress and Average Strain are used as X and Y values for a plot of all 5 cycles. They are both 1785x1 matrices.
Thanks for your time and aid!
Neil
1 commentaire
Andrew Newell
le 5 Juin 2014
Hello, Neil. You'll need to explain what you mean by "too early".
Réponse acceptée
Plus de réponses (1)
Neil
le 6 Juin 2014
0 votes
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!