フィルターのクリア

Maximum value of matrix

2 ビュー (過去 30 日間)
mingcheng nie
mingcheng nie 2022 年 10 月 29 日
コメント済み: mingcheng nie 2022 年 10 月 29 日
Hi there,
If we have a complex matrix A, size of (N,M), is there any efficient way to keep the maximum 6 absolute values in A and set others to be zeros? like abs(A(n,m)), keep the top6 biggest one, then set rest to 0.
Really appreciate for anyone leave a comment.

採用された回答

Kevin Holly
Kevin Holly 2022 年 10 月 29 日
% Generate random matrix
N = 34;
M = 23;
A = rand(N,M);
% Sort from highest to lowest
values = sort(abs(A(:)), 'descend')
values = 782×1
0.9998 0.9985 0.9980 0.9971 0.9965 0.9962 0.9950 0.9924 0.9914 0.9913
% top 6
values(1:6)
ans = 6×1
0.9998 0.9985 0.9980 0.9971 0.9965 0.9962
values(6)
ans = 0.9962
B = (A>=values(6)).*A
B = 34×23
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9980 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9985 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
imshow(B)
  3 件のコメント
Kevin Holly
Kevin Holly 2022 年 10 月 29 日
I would appreciate it if you could accept this answer.
mingcheng nie
mingcheng nie 2022 年 10 月 29 日
sure definitely

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by