Finding maximum of rows, colums, overall in matrix

6 ビュー (過去 30 日間)
Chris
Chris 2013 年 10 月 30 日
コメント済み: Cedric 2017 年 9 月 22 日
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 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 30 日
What have you tried so far with your homework?

サインインしてコメントする。

回答 (1 件)

Image Analyst
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
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
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 ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by