필터 지우기
필터 지우기

Find repeated values in an array, by column and rows (unique function).

조회 수: 2 (최근 30일)
Yro
Yro 2021년 5월 19일
답변: Matt J 2021년 5월 24일
Hi, I want to find the repeated vectors in an array where I have n columns and m rows. For example in the following array:
ARRAY = [
9.04828 8.80036 ...
9.04828 8.80036 ...
9.11259 8.74653 ...
9.04828 8.80036 ...
9.24358 8.74653 ...
8.9823 9.05449 ...
9.02563 8.24793 ...
7.5415 8.94942 ...
7.28989 8.81836 ...
...
]
I want to find the repeated vectors (x1, x2), which are repeated in rows 1, 2 and 4. Using the unique function, I can get the repeated value by defining:
[C1, ia1, ic1] = unique(A(:,1),'stable', 'rows');
but only by columns. How can I get the vector that repeats?
Thanks in advance.

채택된 답변

KSSV
KSSV 2021년 5월 19일
A = [9.04828 8.80036 ;
9.04828 8.80036 ;
9.11259 8.74653 ;
9.04828 8.80036 ;
9.24358 8.74653 ;
8.9823 9.05449 ;
9.02563 8.24793 ;
7.5415 8.94942 ;
7.28989 8.81836 ] ;
[C1, ia1, ic1] = unique(A,'stable', 'rows');
A(ic1==1,:)
  댓글 수: 3
KSSV
KSSV 2021년 5월 24일
You have it caluclated from the function already..... C1 is the array you want.
Yro
Yro 2021년 5월 24일
Thank you very much for your help.
Best regards.

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

추가 답변 (1개)

Matt J
Matt J 2021년 5월 24일
A = [9.04828 8.80036 ;
9.04828 8.80036 ;
9.11259 8.74653 ;
9.04828 8.80036 ;
9.24358 8.74653 ;
8.9823 9.05449 ;
9.02563 8.24793 ;
7.5415 8.94942 ;
7.28989 8.81836 ] ;
C=num2cell(A,1);
[G,ID{1:2}]=findgroups(C{:});
ID=cell2mat(ID)
ID = 7×2
7.2899 8.8184 7.5415 8.9494 8.9823 9.0545 9.0256 8.2479 9.0483 8.8004 9.1126 8.7465 9.2436 8.7465

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by