how to create 3*5 matrix using loop?

조회 수: 9 (최근 30일)
anjala rai
anjala rai 2016년 10월 16일
답변: Walter Roberson 2016년 10월 16일
11) Create a 3 x 5 matrix. Perform each of the following using loops (with if statements if necessary): • Find the maximum value in each column. • Find the maximum value in each row. • Find the maximum value in the entire matrix.
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2016년 10월 16일
it's homework
dpb
dpb 2016년 10월 16일
But I'll note the question doesn't match the HW question -- it doesn't say use a loop to create the array, only for the computation of the various maxima.

댓글을 달려면 로그인하십시오.

답변 (2개)

Austin
Austin 2016년 10월 16일
Where did you become stuck?
The MATLAB Onramp explains creating matricides pretty well. Max function help is here: https://www.mathworks.com/help/matlab/ref/max.html
I thought the hardest part was figuring out what to loop. If you just start typing it in, the repeating commands are easier to identify.
Here is how to find the max of each row with a loop by indexing into each row of the created array:
a=rand(3,5)%There are a bunch of ways to put in better data; try MATLAB Onramp tutorial
b=zeros(1:3);%pre allocating for the row answer
for n=1:3
b(n)=max(a(n,:))%This returns the max of each row as an element of b.
end

Walter Roberson
Walter Roberson 2016년 10월 16일

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by