MATLAB Answers

## Remove the entire row from the matrix on the basis of column having duplicate value

Asked by Ahsan Abbas

### Ahsan Abbas (view profile)

on 30 Mar 2016
Latest activity Commented on by Ahsan Abbas

### Ahsan Abbas (view profile)

on 31 Mar 2016
Accepted Answer by Jan

### Jan (view profile)

Hello Guys I have a matrix A that contains duplicate values in row 3,4 from column 3 to 6. I want to remove the entire 4th row, or both rows, how can i do it without using the loop?. what if i have similar problem in more rows, what's the syntax for this? I want to solve it in 1 line, help me to solve the problem. Thanks

Walter Roberson

### Walter Roberson (view profile)

on 30 Mar 2016
Will the duplicates always be in adjacent rows?
Ahsan Abbas

### Ahsan Abbas (view profile)

on 30 Mar 2016
No it's not, but if we can sort it on the basis of 3rd column then it will be adjacent rows.
Image Analyst

### Image Analyst (view profile)

on 30 Mar 2016
You may have to give up the one line requirement unless you want to just string multiple lines of code together on one line, which you can do. I think you could do that with Jan's 2 line code below.

Sign in to comment.

## 1 Answer

Answer by Jan

on 30 Mar 2016
Edited by Jan

### Jan (view profile)

on 30 Mar 2016
Accepted Answer

This removes all rows of the matrix Data, which have repeated values in the 3rd column. The first occurence is kept:
[C, IA] = unique(Data(:, 3), 'stable');
Data = Data(iA, :);

Ahsan Abbas

### Ahsan Abbas (view profile)

on 31 Mar 2016
Thanks Jan Simon problem is solved...

Sign in to comment.