for loop for reading numbers from a matrix in each row

조회 수: 13 (최근 30일)
Far mah
Far mah 2019년 11월 20일
댓글: Far mah 2019년 11월 20일
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 !

채택된 답변

Erivelton Gualter
Erivelton Gualter 2019년 11월 20일
% 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

추가 답변 (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