フィルターのクリア

Selection of 3 large value from a matrix

1 回表示 (過去 30 日間)
Tinkul
Tinkul 2014 年 4 月 7 日
コメント済み: Tinkul 2014 年 4 月 7 日
How can i select 3 largest value from a matrix and remaining make zero without changing the dimension,For eg A=[1 3 5 8 31 7 4 18] The output should be A=[0 0 0 8 31 0 0 18] Please help

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 7 日
編集済み: Azzi Abdelmalek 2014 年 4 月 7 日
A=[1 3 5 8 31 7 4 18]
[ii,jj]=sort(A,'descend');
A(jj(4:end))=0
Or
A=[1 3 5 8 31 7 4 18]
[ii,jj]=sort(A,'descend');
B=zeros(size(A))
B(jj(1:3))=A(jj(1:3))
  1 件のコメント
Tinkul
Tinkul 2014 年 4 月 7 日
Thank you...Awsome...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by