[Max,index]=max(array,[ ],2)..... Iam using this syntax to find the maximum value of every column but in case of two equal maximum values it returns the first one... how can I solve this?! Thanks

5 件のコメント

Walter Roberson
Walter Roberson 2020 年 2 月 10 日
You have not defined what outcome you would prefer.
Steven Lord
Steven Lord 2020 年 2 月 10 日
That sounds like it's working as it should. From the documentation "If the largest element occurs more than once, then I contains the index to the first occurrence of the value."
What did you expect it to do instead?
Marco Nashaat
Marco Nashaat 2020 年 2 月 10 日
sorry for your trouble....but the problem I'm working on is to find the saddle points of a matrix and now I'm trying this ...
[row,col]=size(matrix);
for I=1:row
for j=1:col
if matrix (I,j)==max(matrix, I)&&matrix (I,j)==min(matrix, j)
indices=[i j;]:
else
indices=[ ]
end
end
end
would it work ...and I could use some help with the syntax!!
Mohymen Kushal
Mohymen Kushal 2020 年 10 月 26 日
if A is a matrix, then max(A,[ ],2) is a column vector containing the maximum value of each row . What is this '2' for ? can anybody explain please. Thanks.
the cyclist
the cyclist 2020 年 10 月 29 日
As clearly stated in the documentation for max, that "2" indicates the matrix dimension along which to take the maximum.

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

 採用された回答

the cyclist
the cyclist 2020 年 2 月 10 日

0 投票

This code will return the row and column indices where the entry is equal to the column's maximum.
[rowIdx,colIdx] = find(A==max(A))

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by