MATLAB Answers

for loop for reading numbers from a matrix in each row

4 views (last 30 days)
Far mah
Far mah on 20 Nov 2019
Commented: Far mah on 20 Nov 2019
Hello
I need to go through a matrix and reach each number row by row. so I think I need a for loop to give me the number first the ones in the first row 1,2,4. then go through the other row and read 3,4,5. these numbers will be used in another statement later with this order.
a=
1 2 4
3 4 5
5 6 2
any help is appreciated !

  0 Comments

Sign in to comment.

Accepted Answer

Erivelton Gualter
Erivelton Gualter on 20 Nov 2019
% Matrix a
a =[1 2 4;
3 4 5;
5 6 2]
% Get size of a
[n, m] = size(a);
% Run throung 1 to number of rows
for i=1:n
a(i,:) % Print all values for the current row
end

More Answers (0)

Sign in to answer this question.

Tags