replace duplicate value by 0 in matrix or vector
조회 수: 16(최근 30일)
표시 이전 댓글
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
채택된 답변
Andrei Bobrov
2019년 10월 15일
편집: Andrei Bobrov
2019년 10월 15일
b = [1 2 1 3];
[a,c] = unique(b,'first');
out = zeros(size(b));
out(c) = a;
추가 답변(2개)
Jos (10584)
2019년 10월 15일
% for small vectors:
b = [1 2 1 3 2 1 4 2]
b(sum(triu(b == b')) > 1) = 0
댓글 수: 0
참고 항목
범주
Find more on Logical in Help Center and File Exchange
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!