how can I create variable number of matrices (arrays) based on an arbitrary input.

I want to write a m-file that measures size of a matrix (I know how to do this) and then creates different number of variables (objects, variables, matrices or what ever you may call it) depending on size (which I don't know how to do). thank you all.

답변 (4개)

Suppose we have a matrix
a=[1 2 ; 3 4; 5 6];
%the size of a is
[n,m]=size(a)
%Now, what do you want to create? you have to tell us, if variables, which variables? if objects, which objects?

댓글 수: 1

thank you.
this is the detailed question:
there is a big matrix as an input with unknown and varying size. lets assume that the matrix has 5 rows, so I want to have 5 different matrices/arrays that present each row separately and maybe the next matrix has more/less row.
so maybe this could help to understand:
A=input('input A: ')
[m,n]=size(A)
now I want to have m different matrices/arrays that each of them represents a row separately! I know I can use A(1,:) but I need to have different and separate matrices.
appreciated

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

Something like this perhaps:
[m, n] = size(A);
if m == 2
CreatedValue = 2;
elseif m > 4 && n < 10
AnotherVariable = 'Hello';
else
SomethingDifferent.Field = 5
end
It looks strange, so perhaps showing us more details would be useful.

댓글 수: 1

thank you.
this is the detailed question:
there is a big matrix as an input with unknown and varying size. lets assume that the matrix has 5 rows, so I want to have 5 different matrices/arrays that present each row separately and maybe the next matrix has more/less row.
so maybe this could help to understand:
A=input('input A: ')
[m,n]=size(A)
now I want to have m different matrices/arrays that each of them represents a row separately! I know I can use A(1,:) but I need to have different and separate matrices.
appreciated

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

thank you.
this is the detailed question:
there is a big matrix as an input with unknown and varying size. lets assume that the matrix has 5 rows, so I want to have 5 different matrices/arrays that present each row separately and maybe the next matrix has more/less row.
so maybe this could help to understand:
A=input('input A: ')
[m,n]=size(A)
now I want to have m different matrices/arrays that each of them represents a row separately! I know I can use A(1,:) but I need to have different and separate matrices.
appreciated
Andrei Bobrov
Andrei Bobrov 2013년 8월 12일
편집: Andrei Bobrov 2013년 8월 12일
use cell arrays:
out = num2cell(A,2); % each cell - your new matrix

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 8월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by