replace duplicate value by 0 in matrix or vector
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Andrei Bobrov
on 15 Oct 2019
Edited: Andrei Bobrov
on 15 Oct 2019
b = [1 2 1 3];
[a,c] = unique(b,'first');
out = zeros(size(b));
out(c) = a;
More Answers (2)
Jos (10584)
on 15 Oct 2019
% for small vectors:
b = [1 2 1 3 2 1 4 2]
b(sum(triu(b == b')) > 1) = 0
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!