How to find maximum without duplicates?

I have the matrix, A = [1 2 1 0 0 2; 2 1 4 2 0 0; 1 1 0 2 1 1; 1 1 0 1 4 2] I understand that max(A) gives the maximum for each column,but how do I create a logical array locating the maximum of each column? If there is a tie, I just want to consider the first occurrence of the maximum.

5 件のコメント

Paolo
Paolo 2018 年 6 月 3 日
By 'tie' you refer to the case where the same max value appears twice in the column? As is the case for number 2, in columns 4 and 6 of your example?
Zev Hirt
Zev Hirt 2018 年 6 月 3 日
yeah
Paolo
Paolo 2018 年 6 月 3 日
I'm not sure I understand though, how can you find the max if you do not compare all values?
If the output of max(A) is
2 2 4 2 4 2
What is your desired output for matrix A?
Zev Hirt
Zev Hirt 2018 年 6 月 3 日
I edited the question. For example, if I do A == max(A), I will have a logical one twice in column 4 and 6.
Zev Hirt
Zev Hirt 2018 年 6 月 3 日
編集済み: Zev Hirt 2018 年 6 月 3 日
My ultimate desired output is the value of the row of the maximum value in each column of A.

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

 採用された回答

Jan
Jan 2018 年 6 月 3 日
編集済み: Jan 2018 年 6 月 3 日

0 投票

A = [1 2 1 0 0 2; 2 1 4 2 0 0; 1 1 0 2 1 1; 1 1 0 1 4 2];
[v, ind] = max(A, [], 1);
Now ind is the row index of the first maximum value per column.
And a "logical array locating the maximum of each column":
siz = size(A);
L = false(siz);
L(sub2ind(siz, ind, 1:siz(2))) = true;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

製品

リリース

R2018a

質問済み:

2018 年 6 月 3 日

編集済み:

Jan
2018 年 6 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by