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

3 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

KSSV
KSSV el 6 de En. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by