How to split a nxn matrix into n vectors
1 回表示 (過去 30 日間)
古いコメントを表示
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
採用された回答
その他の回答 (3 件)
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
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
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!