find the Unique Coupled-value in a vector and eliminate the zero-coupled values

1 view (last 30 days)
Hello everybody,
Thank you for the interest for my question and your help I am not successful to find an algorithm which permits to get unique coupled-values in a two-rows vector. Here is the example:
vect=[
1 599 256 599 256 0 0 0 0 0 324 599 256 256 599
171 171 150 171 150 150 171 0 0 0 171 150 0 171 150
]
The results that I want is
res=
[
1 599 256 0 0 324 599 256 256
171 171 150 150 171 171 150 0 171
]
Could you please provide an algorithm for me ?
Thanks in advance,
gringoire lee

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 24 Aug 2011
[a b c] =unique(vect','rows','first')
out = sortrows([a,b],3)
res = out(any(out(:,1:2),2),1:2)'

More Answers (0)

Categories

Find more on Environment and Clutter 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!