Hello Everyone, I'm looking for your help for the following problem

1 回表示 (過去 30 日間)
Keyre
Keyre 2018 年 3 月 5 日
コメント済み: Keyre 2018 年 3 月 6 日
Use the matrix given on the first link.I need a matlab code that can generate on the second link. Thanks!
  5 件のコメント
Keyre
Keyre 2018 年 3 月 5 日
The maximum value for each column but it become the second or third maximum if the row side already two maximum values are selected
Jan
Jan 2018 年 3 月 5 日
@Keyre: I do not understand your explanations.

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

採用された回答

Akira Agata
Akira Agata 2018 年 3 月 5 日
The second image you uploaded is not the correct maximum value array for each column... Anyway, let me try to do this without using for-loop:
A = [17 14 18 15 14 19;...
1 5 3 30 8 14;...
20 2 16 7 13 11];
idx = bsxfun(@eq,A,max(A));
A(~idx) = NaN;
The result is:
>> A
A =
NaN 14 18 NaN 14 19
NaN NaN NaN 30 NaN NaN
20 NaN NaN NaN NaN NaN
  3 件のコメント
Akira Agata
Akira Agata 2018 年 3 月 6 日
Hi Keyre-san,
Thank you for the clarification. Here is my 2nd try. I hope this will be helpful somehow.
A = [17 14 18 15 14 19;...
1 5 3 30 8 14;...
20 2 16 7 13 11];
idx = false(size(A));
for kk = 1:size(A,2)
[~,pt] = sort(A(:,kk),'descend');
for ll = 1:3
if nnz(idx(pt(ll),:)) < 2
idx(pt(ll),kk) = true;
break;
end
end
end
A(~idx) = NaN;
And here is the result:
>> A
A =
NaN 14 18 NaN NaN NaN
NaN NaN NaN 30 NaN 14
20 NaN NaN NaN 13 NaN
Keyre
Keyre 2018 年 3 月 6 日
Dear Akira Agata, really helpful. Thanks!

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

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2018 年 3 月 5 日
I'll provide a lead. I think the rest should be relatively easy.
A = [17 14 18 15 14 19;...
1 5 3 30 8 14;...
20 2 16 7 13 11];
[~,IndexMatrix]=sort(A,'descend');
IndexMatrix =
3 1 1 2 1 1
1 2 3 1 3 2
2 3 2 3 2 3
The first row of IndexMatrix is what you need to work on. Starting from the third column, do a loop, compare it with all the previous number to see if it occurs twice already. If it does, replace it with the number in the same column but next row in IndexMatrix. You need to do this in a while-loop because the next number could also occur twice already, although in this one case, it didn't happen.
  1 件のコメント
Keyre
Keyre 2018 年 3 月 6 日
Dear Fangjun Jiang, Thanks for your helpful direction

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by