Calling matrices automatically with matlab

I have three matrices:
elem1 = (1,1) elem2 = (2,2) elem3 = (3,3)
I want to call these matrices in a for loop such as
for i=1:3
A(i,1)=elem(i)
end
How should I write elem(i) correctly to call elem matrices?

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 23 日
編集済み: Azzi Abdelmalek 2013 年 12 月 23 日

0 投票

elem1 = [1,1]
elem2 = [2,2]
elem3 = [3,3]
for k=1:3
eval(sprintf('a=elem%d',k));
A(k,1:n)=a
end
Image Analyst
Image Analyst 2013 年 12 月 23 日

0 投票

Simply do this:
A(1,:) = elem1;
A(2,:) = elem2;
A(3,:) = elem3;

この質問は閉じられています。

質問済み:

2013 年 12 月 23 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by