How can I strip duplicates?

조회 수: 2 (최근 30일)
Holm Roeser
Holm Roeser 2021년 4월 8일
편집: per isakson 2021년 10월 13일
I wish to remove all duplicate rows based off of the first column. That is, I want to just strip the excess away. I am struggling to understand how to implement "unique" here. Thanks in advance
  댓글 수: 5
Cris LaPierre
Cris LaPierre 2021년 4월 9일
Ah, got it. Thanks.
per isakson
per isakson 2021년 10월 13일
편집: per isakson 2021년 10월 13일
The values in the first column are not whole numbers. Thus uniquetol is appropriate.

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2021년 4월 9일
If you want
  1. remove duplicates only based on values in the first column
  2. Do not want the returned values be sorted
then you need to do this
in=[[5;5;5;4;4;4;3;3;3;1],(1:10)'];
[~, index]=unique(in(:,1),'stable');
out=in(index,:)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by