How to use for loop to read the value of each row of a matrix

3 ビュー (過去 30 日間)
rakesh kumar
rakesh kumar 2022 年 1 月 6 日
コメント済み: rakesh kumar 2022 年 1 月 6 日
Ih have a permutation matrix P=[ 1 1;1 2;2 1;2 2] . I want to use,for loop to take the vale of each row and use in the two by two matrix A(:, :, i), i varies from first column to last column,so that I can add and it with another two by two matrix B. Like C= B+ A(:, :, i). After the end of each row of P, it should go to next row of P and calculate new value of C.

採用された回答

KSSV
KSSV 2022 年 1 月 6 日
Read about for loop and matlab indexing. It is an easy task.
% EXample demo
A = rand(3,4) ;
[m,n] = size(A) ;
for i = 1:m
r = A(i,:) % extract each row
end

その他の回答 (0 件)

カテゴリ

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