Extracting rows in row-wise manner. How to do this?

1 回表示 (過去 30 日間)
S Priya
S Priya 2021 年 9 月 16 日
回答済み: Image Analyst 2021 年 9 月 16 日
Suppose,a matrix A, A=[1 2 3 4; 1 0 2 8; 1 2 3 6....]
Size(A)=100 4
And I want to extract each row in a row-wise manner (ie.row1,then row2, row3....)and then place it in seperate B matrix where 1 row will be used at a time.
How to do this?
  1 件のコメント
per isakson
per isakson 2021 年 9 月 16 日
Tags in this forum shall not have a leading #.

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

回答 (2 件)

KSSV
KSSV 2021 年 9 月 16 日
Question sounds very silly. You can use a lloop.
A = rand(100,4) ;
B = zeros(100,4) ;
for i = 1:100
thisrow = A(i,:) ;
B(i,:) = thisrow ;
end

Image Analyst
Image Analyst 2021 年 9 月 16 日
Try this:
[rows, columns] = size(A);
for row = 1 : rows
% Extract a row of A (all columns of it) into a new row vector, B.
B = A(row, :)
% Now use B in whatever way you want. It will get overwritten on each iteration, but that shouldn't matter.
end

カテゴリ

Help Center および File ExchangeSignal Attributes and Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by