How to split a nxn matrix into n vectors

조회 수: 2 (최근 30일)
Max
Max 2012년 11월 16일
Hi at all, I want to split a nxn matrix in n vectors:
M= [1 2 3 ; 4 5 6 ; 7 8 9];
in
m1 = [1 2 3];
m2 = [4 5 6];
m3 = [7 8 9];
I know that m1=M(1,:);
m2=M(2,:) ... ...
m(n)=M(n,:)
but if the matrix is very large how can I resolve? Thanks a lot
Max
  댓글 수: 2
Yash
Yash 2012년 11월 16일
reshape it.
Max
Max 2012년 11월 16일
How? I try
[X Y]= size(M)
a=reshape(M,X,Y);
but a == M
(I certainly wrong)

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

채택된 답변

Max
Max 2012년 11월 17일
편집: Max 2012년 11월 17일
Ok, thanks at everybody!
Sorry for the wrong word but i not speak English very goog; with struct I mean cell array, sorry ;)
However, how i can have single value in one cell?

추가 답변 (3개)

Andrei Bobrov
Andrei Bobrov 2012년 11월 16일
m = num2cell(M,2);
your m1 -> m{1}
  댓글 수: 1
Max
Max 2012년 11월 16일
Thanks, but I need separate values in the vector... not "all in one" :D

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


Jan
Jan 2012년 11월 16일
Using a list of variable like "m1, m2, ..." is a really bad idea and it increases the complexity of programs without any advantage. Andrei's suggestion to use a cell array is much better. See
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2012년 11월 16일
편집: Andrei Bobrov 2012년 11월 16일
eg
M= [1 2 3 ; 4 5 6 ; 7 8 9];
m = num2cell(M,2);
out = polyder(m{1:2}); % for your version out = polyder(m1,m2);
Jan
Jan 2012년 11월 16일
"Struct"? Structs have field names, but I do not see any field names here. Do you mean "cell array"?
I think that Andrei has guessed already, what you are trying to do. But in general in is more efficient, when you explain exactly, what you are trying to do.

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


Matt Fig
Matt Fig 2012년 11월 16일
Jan is correct. Doing this is a bad idea. If you need to use the POLYDER function on each row of a large array, there are several ways to do it without making many variables.
M = randi(4,6,4);
N = num2cell(M,2);
PD = cellfun(@polyder,N,'Un',0)
Now PD{1} is the POLYDER of M(1,:), PD{2} is the POLYDER of M(2,:), etc.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by