Building a code that saves the output of each loop as a vector
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Abhimanyu Kashyap
2013-5-14
编辑:Abhimanyu Kashyap
2013-5-14
Hi, Please post your code linewise. Right now its difficult to understand. But from what you said I gather, you want to save stresses/forces that comes out as vector in one loop. You want to carry out 40 loops and each time save that vector of forces/stress whatever. To do this, cells are very convenient..
suppose F= vector of forces.
>>force_cell= cell(1,40); % initialize a cellarray containing 40 cells.
>>for i=1:40
force_cell{i}= F ;
end
Now to you have all 40 vectors stored in cells. Suppose you want to call lets say 25th force vector. do this,
>>force_cell{25}
answer will show "F" vector corresponding to 25th loop.
Hope this helps.. Cheers..!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stress and Strain 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!