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

1 次查看(过去 30 天)
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 个)

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 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by