Changing value when first time a value appears
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mia Dier
il 14 Gen 2021
Commentato: Mia Dier
il 14 Gen 2021
A=[1; 1; 1; 1; 2; 2; 4; 4; 4; 4]
B=[4; 2; 7; 9; 5; 0; 2; 6; 1; 0]
I want to change the values of B to NaN whenever a value in A appears for the first time. i.e.
B=[NaN; 2; 7; 9; NaN; 0; NaN; 6; 1; 0]
0 Commenti
Risposta accettata
Walter Roberson
il 14 Gen 2021
A=[1; 1; 1; 1; 2; 2; 4; 4; 4; 4]
B=[4; 2; 7; 9; 5; 0; 2; 6; 1; 0]
[~, ia] = unique(A, 'stable')
B(ia) = nan
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!