replace duplicate value by 0 in matrix or vector
古いコメントを表示
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
採用された回答
その他の回答 (2 件)
Adam
2019 年 10 月 15 日
[C,ia] = unique( b );
b( setdiff( 1:numel(b), ia ) ) = 0;
Jos (10584)
2019 年 10 月 15 日
% for small vectors:
b = [1 2 1 3 2 1 4 2]
b(sum(triu(b == b')) > 1) = 0
カテゴリ
ヘルプ センター および File Exchange で Discrete Data Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!