Eliminate duplicates of nonzero elements but keep zeros
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I have a logical array. I want to eliminate the duplicates of the 1s but keep all the zeros intact.
Here's an example of what I want.
A = [0 1 0 1 1 0 0 0 0 0 1 1 1 0 1]
new matrix = [0 1 0 1 0 0 0 0 0 1 0 1].
The zeros are the same but all the duplicate 1s after the first are eliminated.
Answers (2)
Azzi Abdelmalek
on 27 Nov 2013
A = [0 1 0 1 1 0 0 0 0 0 1 1 1 0 1]
A(strfind(A,[1,1]))=[]
2 Comments
Alice
on 27 Nov 2013
Azzi Abdelmalek
on 27 Nov 2013
A = [0 1 0 1 1 0 0 0 0 0 1 1 1 0 1];
B=A;
B(strfind(B,[1,1]))=[]
Andrei Bobrov
on 27 Nov 2013
A(~([false,diff(A)] == 0 & A == 1))
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!