Building a code that saves the output of each loop as a vector
Show older comments
I am new to MATLAB, I am trying to build a code that saves the output of each loop as a vector, i.e after making 40 loops I should have 40 vectors (each vector has different length) so that I can do further analysis. Please help?
E = 215000
K = 853
n = .166666666666666666666666666667
incr = 5
peaks = 10
stress = [0 20 -160 150 -40 330 -40 170 -20 180]
if stress(2)<stress(1)
incr = - incr
end
stress12 = stress(1):incr:stress(2)
strain12 = (stress12/E) + (stress12/K).^(1/n)
conststress = stress12(end)
conststrain = strain12(end)
plot(strain12,stress12)
hold on
for j = 2:1:peaks-1
k = j+1;
if stress(k)<stress(j)
incr = - incr;
stressjk = stress(j):incr:stress(k)
strainjk = conststrain+(((stressjk-conststress)/E)-2*((stressjk-conststress)/(2*K)).^(1/n))
conststress = stressjk(end)
conststrain = strainjk(end)
else
incr = abs(incr)
stressjk = stress(j):incr:stress(k)
strainjk = (((stressjk-conststress)/E)+2*((stressjk-conststress)/(2*K)).^(1/n))+conststrain
conststress = stressjk(end)
conststrain = strainjk(end)
end
plot(strainjk,stressjk)
hold on
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!