COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Remove only concecutive repetitions in an array/matrix

• Email
• 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

See related articles to this posting

```One approach:

B = A([true;logical(diff(A(:,2)))],:)
```
 1

```"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?

```
 0

```SORT along the rows first.
```
 0

3 Replies
785 Views

Similar Articles

12/7/2013 12:29:25 AM
page loaded in 4310 ms. (0)