Splitting matrix into row vectors

38 ビュー (過去 30 日間)
Pedro Oliveira
Pedro Oliveira 2017 年 11 月 28 日
コメント済み: Lodovico Morando 2020 年 9 月 2 日
Hi,
I have a matrix (with varying dimensions so those aren't important) and I want to split it into vectors such that the first vector is the first row, the second vector is the second row, etc.
I need to do this since these vectors will be the input to a function that can only take row vectors. What is the best way to split the matrix into row vectors?
Thank you.

回答 (1 件)

Stephen23
Stephen23 2017 年 11 月 28 日
編集済み: Stephen23 2017 年 11 月 28 日
Simply use indexing:
mat = [...]; % your matrix
for k = 1:size(mat,1)
vec = mat(k,:); % each row of mat
... do whatever with vec
end
C = num2cell(mat,2);
for k = 1:numel(C)
vec = C{k};
... do whatever with vec
end
  1 件のコメント
Lodovico Morando
Lodovico Morando 2020 年 9 月 2 日
Yea but now all the vectors have the same name..is there a way to give each of them a different name according to the number of columns or raws there are?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by