How to extract individual vectors out of a matrix and save them with different names?

1 回表示 (過去 30 日間)
Hi all, so I have a Matrix A (270,10) and I want to create, for each column, a different vector, caled for example b1, b2, b3 and so forth...
so here I have the code:
notes: size(varargout,2) = 270
for h = 1: size(varargout,2)
for v=1:10
vectors = A(:,v);
end
end
it keeps giving me matrixes, when I wanted separated vectors...
Can anyone help me?
Thanks!!
  2 件のコメント
Stephen23
Stephen23 2019 年 9 月 10 日
"...caled for example b1, b2, b3 and so forth..."
Using numbered varaibles is a sign that you are doing something wrong.
It is much simpler and much more efficient to use indexing.
Ana Bianco
Ana Bianco 2019 年 9 月 10 日
And how would that be??

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

採用された回答

madhan ravi
madhan ravi 2019 年 9 月 10 日
編集済み: madhan ravi 2019 年 9 月 10 日
What you're doing is not a good idea see https://in.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval , use a cell array or a ND array instead.
b=num2cell(matrix,1);
celldisp(b)
  3 件のコメント
madhan ravi
madhan ravi 2019 年 9 月 10 日
All the vectors are saved in b already.
Ana Bianco
Ana Bianco 2019 年 9 月 10 日
Perfect, thanks for the help!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by