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

3 views (last 30 days)
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.

Accepted Answer

KSSV
KSSV on 6 Jan 2022
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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!