Delete all values except the max value

1 回表示 (過去 30 日間)
Dion Theunissen
Dion Theunissen 2021 年 3 月 1 日
コメント済み: Dion Theunissen 2021 年 3 月 1 日
Hi,
I have a 10x10 matrix Y. Now i want to make all elements 0 except the highes value of a row. So for example I have a matrix:
A = [3,10,8
4,8,1]
I want
B = [0,10,0
0,8,0]
Thanks

採用された回答

KSSV
KSSV 2021 年 3 月 1 日
A = [3,10,8
4,8,1] ;
[val,id] = max(A,[],2) ;
idx = A<val ;
A(idx) = 0 ;
A
A = 2×3
0 10 0 0 8 0
  1 件のコメント
Dion Theunissen
Dion Theunissen 2021 年 3 月 1 日
Perfect, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by