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

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

KSSV
KSSV il 6 Gen 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by