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

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by