replace duplicate value by 0 in matrix or vector
Mostrar comentarios más antiguos
How do we replace duplicate value by 0 in matrix or vector ?
for example
Input:
b = 1 2 1 3
Output::
b= 1 2 0 3
Thanks
Respuesta aceptada
Más respuestas (2)
Adam
el 15 de Oct. de 2019
[C,ia] = unique( b );
b( setdiff( 1:numel(b), ia ) ) = 0;
Jos (10584)
el 15 de Oct. de 2019
% for small vectors:
b = [1 2 1 3 2 1 4 2]
b(sum(triu(b == b')) > 1) = 0
Categorías
Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!