Delete all values except the max value

7 Ansichten (letzte 30 Tage)
Dion Theunissen
Dion Theunissen am 1 Mär. 2021
Kommentiert: Dion Theunissen am 1 Mär. 2021
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

Akzeptierte Antwort

KSSV
KSSV am 1 Mär. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by