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.

Answers (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 Comment

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

Sign in to comment.

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 Comment

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

Sign in to comment.

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
use cell arrays:
out = num2cell(A,2); % each cell - your new matrix

Asked:

on 8 Aug 2013

Community Treasure Hunt

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

Start Hunting!