How to save outputs in a while loop

I would like to save each output of the following while loop, however I do not know how to do this.
while i<a
i=1+i;
E=members(i,4);
A=members(i,5);
start=members(i,2); %the starting joint of the member
last=members(i,3); %The end joint of the member
Xb=joints(start,2); %Beginign x coordinate
Xe=joints(last,2); %Ending x coordinate
Yb=joints(start,3); %Begingin y cooridnate
Ye=joints(last,3); %Ending y coordinate
[K,T]=stiff_truss(E,A,Xb,Yb,Xe,Ye); %Creates the K,T for each member
end

回答 (1 件)

KSSV
KSSV 2017 年 3 月 1 日
編集済み: KSSV 2017 年 3 月 1 日

0 投票

Say you want to store K,T inside the loop. Do as follows:
iwant = cell(a,2) ;
while i<a
i=1+i;
E=members(i,4);
A=members(i,5);
start=members(i,2); %the starting joint of the member
last=members(i,3); %The end joint of the member
Xb=joints(start,2); %Beginign x coordinate
Xe=joints(last,2); %Ending x coordinate
Yb=joints(start,3); %Begingin y cooridnate
Ye=joints(last,3); %Ending y coordinate
[K,T]=stiff_truss(E,A,Xb,Yb,Xe,Ye); %Creates the K,T for each member
iwant{i,1} = K ;
iwant{i,2} = T ;
end

2 件のコメント

Krasho4
Krasho4 2017 年 3 月 1 日
I added the new code into and I received an error message saying sub-scripted assignment dimension mismatch. It specified the line iwant(i,:)=[K,T];
KSSV
KSSV 2017 年 3 月 1 日
編集済み: KSSV 2017 年 3 月 1 日
Ohh...then K and T is a matrix? Edited my answer, considering K and T as a matrix.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

タグ

質問済み:

2017 年 3 月 1 日

編集済み:

2017 年 3 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by