Finding maximum of rows, colums, overall in matrix
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
Image Analyst
am 30 Okt. 2013
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 Kommentare
Image Analyst
am 31 Okt. 2013
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
am 22 Sep. 2017
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.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!