MATLAB: Counting the unique values

matrix manipulation

I have a values
out=
c1 c2,,,,,,,,,,,,,,,,,,,,,c5
'gene1' 'd' 'u' 'd' 'u' 'd'
'gene2' 'u' 'u' 'u' 'u' 'd'
'gene3' 'u' 'u' 'd' 'u' 'u'
'gene4' 'd' 'u' 'u' 'd' 'd'
'gene5' 'u' 'u' 'u' 'u' 'd'
'gene6' 'd' 'u' 'u' 'u' 'u'
'gene7' 'd' 'u' 'd' 'u' 'u'
Taking the first column 'c1' value for gene1 is 'd' this value must be compared with all other column if there is more than 3 same vales it should be displayed,,Only first clumn must be compared with others columns
in 1st col there are 3d's ,2nd col 4u's(since 1st col is u),3rd col
4u's,,,,,,,,,,,6&7th gene's there are only 1 ans 2 d's respectively,so it should be deleted
So i need output as
'gene1' 'd' 'u' 'd' 'u' 'd'
'gene2' 'u' 'u' 'u' 'u' 'd'
'gene3' 'u' 'u' 'd' 'u' 'u'
'gene4' 'd' 'u' 'u' 'd' 'd'
'gene5' 'u' 'u' 'u' 'u' 'd'
Pleae help

Best Answer

Hello Pat,
first idea i came up with:
A = {'','c1','c2','c3','c4','c5';
'gene1' 'd' 'u' 'd' 'u' 'd';...
'gene2' 'u' 'u' 'u' 'u' 'd';...
'gene3' 'u' 'u' 'd' 'u' 'u';...
'gene4' 'd' 'u' 'u' 'd' 'd';...
'gene5' 'u' 'u' 'u' 'u' 'd';...
'gene6' 'd' 'u' 'u' 'u' 'u';...
'gene7' 'd' 'u' 'd' 'u' 'u'};
limit = 3;
F = cell2mat(A(2:end,2:end));
A(logical([0;sum(bsxfun(@eq,F,F(:,1)),2)>=limit]),:);
Hopefully it will help you.
Freddy