Changing value when first time a value appears
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mia Dier
el 14 de En. de 2021
Comentada: Mia Dier
el 14 de En. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 14 de En. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!