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 で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!