Find the first position of maximum value in a Matrix

32 次查看(过去 30 天)
Hello everyone,
Suppose there can be the max value at more than one location, how can I catch the first max value.
A = [6;7;21;4;9;21;5;1];
max(A(:))
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes colsOfMaxes] = find(A == maxValue)
ans =
21
rowsOfMaxes =
3
6
colsOfMaxes =
1
1
Then I want it to be:
ans =
21
rowsOfMaxes =
3
colsOfMaxes =
1
Can anyone please help me?
  1 个评论
the cyclist
the cyclist 2014-5-5
I'm confused as to why you are referring to rows and columns, when the original input is a vector, not a matrix.

请先登录,再进行评论。

采纳的回答

José-Luis
José-Luis 2014-5-5
编辑:José-Luis 2014-5-5
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes colsOfMaxes] = find(A == maxValue,1,'first')
Please accept an answer if it helped you.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by