Finding maximum of rows, colums, overall in matrix
조회 수: 6 (최근 30일)
이전 댓글 표시
I am completely stumped on a problem here. I've been playing around with it for hours now to no avail. I have to create a script that will prompt the user to enter their desired matrix dimensions. Then perform each of the following using loops (Not using that ‘max’ built in function’ but you may use 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.
댓글 수: 1
답변 (1개)
Image Analyst
2013년 10월 30일
Hours? Wow. Hint:
[rows, columns] = size(yourMatrix);
maxOfRows = -inf * ones(1, rows);
maxOfColumns - .....
for col = 1 : columns
for row = 1 : rows
if .... > ...
end
end
end
I hope that's enough to get you started. See if you can fill it out from there.
댓글 수: 3
Image Analyst
2013년 10월 31일
You want to see if your matrix is greater than the max for the row and column the current element is in, so the first part is right, but you don't want to compare it to zero, you want to compare it to the latest max value for that row and column, don't you? And if it is, you need to store that value into the max arrays. And to check the current location, you check mat(row, col) because row and col are the indexes which change as you move through the array. rows and columns don't change so mat(rows, columns) refers to the very last (lower right) corner of the matrix and never changes.
if mat(row, col) > maxOfRows(row)
% Save this value in our max matrix.
maxOfRows(row) = mat(row, col);
end
if mat(row, col) > maxOfCols(col)
maxOfCols(col).........
Try to finish that.
Cedric
2017년 9월 22일
Catherine, start a new thread, reference this one if necessary, and give an example. The more specific you are, the more likely you'll get an answer.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!