필터 지우기
필터 지우기

Building a code that saves the output of each loop as a vector

조회 수: 2 (최근 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

채택된 답변

Abhimanyu  Kashyap
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..!
  댓글 수: 1
Mohammed
Mohammed 2013년 5월 14일
Thank you very much for your help, I did what you suggested and it looks working. I think now I can proceed doing further analysis.
Regards

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by