Calling automatically created matrices

조회 수: 9 (최근 30일)
Selman
Selman 2013년 12월 26일
편집: Matt J 2013년 12월 27일
Using eval code I have created following matrices:
A1 = [0;0] A2 = [1;1] A3 = [2;2]
I want to call these matrices in a for loop such as;
for i=1:3
X=A(i)
end
Here A(i) should correspond to A1, A2 and A3 for increasing i values and X matrice will be equal to A1, A2 and A3 with each loop. Ultimately it will be equal to A3 obviously.
How can I write A(i) in correct form?

답변 (2개)

Walter Roberson
Walter Roberson 2013년 12월 26일

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 26일
Instead of creating all those matrices, it's better to create one cell array containing all your matrices
X{1}=[0;0]
X{2}=[1;1]
X{3}=[2;2]
  댓글 수: 1
Matt J
Matt J 2013년 12월 27일
편집: Matt J 2013년 12월 27일
Even better, since they're the same size, to put them all in one matrix
A=[0 1 2; 0 1 2];
for i=1:3
A(:,i)
end

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by