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개)
Azzi Abdelmalek
2013년 8월 8일
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?
Jan
2013년 8월 8일
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.
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!