Remove only concecutive repetitions in an array/matrix

  • Follow


Is there a way to remove only consecutive repetitions in an array? The UNIQUE function removes every other repietition irrespective of ther order

For example I have a matrix as follows

1    6
2    6
3    5
4    20
5    18
6    7
8    5
9    5
10  5
11  20
12  6

the  matirx  after suppression  of consecutively repeated elements should be

1    6
3    5
4    20
5    18
6    7
8     5
11   20
12   6


In the consecutively repeates  values i just need the first occurance (or any one of them). Is there a way to do this?

Any help is appreciated.

Thanks,
Nodal.
0
Reply Nodal 3/5/2010 6:39:25 PM

One approach:

B = A([true;logical(diff(A(:,2)))],:)
1
Reply Matt 3/5/2010 6:57:22 PM


"Matt Fig" <spamanon@yahoo.com> wrote in message <hmrk6h$4rg$1@fred.mathworks.com>...
> One approach:
> 
> B = A([true;logical(diff(A(:,2)))],:)

This helps me as well.  Thanks.  I have  similar problem, but also have a reciprocal repeat where both the cases below are considered repeats on the instrument.  Just need to retain the first value encountered.

matrix
1 2 
2 1
2 3
2 3

out matrix
1 2
2 3

any suggestions?

http://www.mathworks.com/matlabcentral/newsreader/view_thread/276030#725037
0
Reply Jason 3/10/2010 7:30:25 PM

SORT along the rows first.
0
Reply Matt 3/10/2010 8:11:05 PM

3 Replies
709 Views

(page loaded in 0.053 seconds)

Similiar Articles:








7/23/2012 12:14:35 AM


Reply: