make a column matrix with outputs of a for loop

3 ビュー (過去 30 日間)
fatima hd
fatima hd 2015 年 7 月 20 日
回答済み: David Schubert 2015 年 7 月 20 日
I have a for loop and I want the outputs of each iteration to sit in a column matrix. for example i have the code below:
for i=1:5
a=[1 2; i 3]
[P,Q]=eig(a);
end
for the first iteration Q(i=1)=[0.2679 0; 0 3.731], for second iteration I have Q(i=2)=[-0.2361 0; 0 4.2361] and so on. I want to construct a 10*1 column matrix in which all the outputs are after each other like this:
S=[0.2679 3.731 -0.2361 4.2361 ....]
but I really don't know how. it would be appreciated if u help me.
  1 件のコメント
Mathieu
Mathieu 2015 年 7 月 20 日
編集済み: Mathieu 2015 年 7 月 20 日
So you want to concatenate some vectors? Because if yes:
b = [];
for i=1:1:5
a = [1 2]
b = [b a];
end
And the result is a vector with [1 2 1 2 1 2 1 2 1 2] (5 times the vector a)

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

採用された回答

David Schubert
David Schubert 2015 年 7 月 20 日
Use diag(Q) to obtain only the eigenvalues on the diagonal of Q, and then concatenate:
mat = [];
for i=1:5
a=[1 2; i 3];
[P,Q]=eig(a);
mat = [mat; diag(Q)];
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by