How I find four or five colunms with distict rows from a table

조회 수: 1 (최근 30일)
Umme ruman Wattoo
Umme ruman Wattoo 2023년 1월 19일
답변: David Hill 2023년 1월 19일
I have a table with 46 columns and 115 rows and I have to find 3 or 4 or 5 such columns that all have distinct rows.In that 4 columns there should not be repeatation in entire 115 rows
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2023년 1월 19일
you simply have to test each column and see if you have 115 unique values
read doc / help of unique

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

답변 (1개)

David Hill
David Hill 2023년 1월 19일
First convert your table into a matrix using table2array()
A=randi(100,115,64);
k=nchoosek(1:64,5);%all combinations of 5 columns (change for 3 and 4)
y=[];
for m=1:size(k,1)
t=A(:,k(m,:));
t=unique(t,'rows');
if size(t,1)==115
y=[y,m];%all rows of k that meet the condition
end
end
k(y,:)%all combinations of 5 columns where all 115 rows are unique

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by