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

조회 수: 1 (최근 30일)
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
  댓글 수: 3
Ahsan Abbas
Ahsan Abbas 2016년 3월 30일
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 2016년 3월 30일
편집: Image Analyst 2016년 3월 30일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2016년 3월 30일
편집: Jan 2016년 3월 30일
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, :);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by