how to convert a 3*3 matrix into 1*9 using for loop

5 ビュー (過去 30 日間)
Gourav Tanwar
Gourav Tanwar 2019 年 8 月 18 日
コメント済み: darova 2019 年 8 月 18 日
i want to convert a 3*3 into 1*9 matrix using for loop
can anyone help

回答 (2 件)

madhan ravi
madhan ravi 2019 年 8 月 18 日
reshape(matrix,1,[]) % no loops needed , the beauty of MATLAB is the tasks are far simpler than most think.

Rob Weh
Rob Weh 2019 年 8 月 18 日
Use reshape to do this. However, if you really want it in a loop for some reason use:
A=magic(3);
B=zeros(numel(A),1);
for ii=1:numel(A)
B(ii)=A(ii);
end
  1 件のコメント
darova
darova 2019 年 8 月 18 日
Remember also (no matter: reshape or loop):
A = [1 2 3
4 5 6
7 8 9];
B = reshape(A,1,[]); % or A(:) or "for" loop
>> B
1 4 7 8 5 2 9 6 3

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by