replace duplicate value by 0 in matrix or vector
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (2)
Adam
le 15 Oct 2019
[C,ia] = unique( b );
b( setdiff( 1:numel(b), ia ) ) = 0;
Jos (10584)
le 15 Oct 2019
% for small vectors:
b = [1 2 1 3 2 1 4 2]
b(sum(triu(b == b')) > 1) = 0
Catégories
En savoir plus sur Discrete Data Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!