Combining unique values and counting
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
in result{1,1}
'Pr1' 'P'
'Par2' 'PSO'
'Par3' 'MPSO'
'Par4' 'SOP'
'Par5' 'MPSO'
'Par6' 'SOPM'
'Par7' 'SOP'
Is it possible to get the result as
result{1,1}
'Par1' 'P'
'Par2' 'PSO'
'Par4' 'SOP'
'Par7' 'SOP'
'Total' 3 (PSO ,SOP are same)
'Pr1' 'P'
'Par3' 'MPSO'
'Par5' 'MPSO'
'Par6' 'SOPM'
'Total' 3 (MPSO,SOPM are same)
plese help
2 Commenti
Jan
il 5 Set 2012
The relation between the inputs and the outputs is not clear. Please add the required details.
Risposta accettata
Andrei Bobrov
il 5 Set 2012
Modificato: Andrei Bobrov
il 5 Set 2012
one way
The initial data cell array result
result={{
'Pr1' 'P'
'Par2' 'PSO'
'Par3' 'MPSO'
'Par4' 'SOP'
'Par5' 'MPSO'
'Par6' 'SOPM'
'Par7' 'SOP'};
{
'Pr1' 'P'
'Par2' 'POS'
'Par3' 'MPSO'
'Par4' 'SOP'
'Par5' 'MPSO'
'Par6' 'SPO'
}}
r = result;
for jj = 1:numel(r)
w = r{jj};
[b,b,b] = unique(cellfun(@sort,w(2:end,2),'un',0));
c = histc(b,1:max(b));
[i1,i1] = sort(b);
n = numel(c);
d = reshape([repmat({w(1,:)},n,1),mat2cell(w(i1+1,:),c,size(w,2)),...
num2cell([repmat({'Total'},n,1) num2cell(c)],2)]',[],1);
r{jj} = cat(1,d{:});
end
3 Commenti
Più risposte (1)
Azzi Abdelmalek
il 5 Set 2012
Modificato: Azzi Abdelmalek
il 5 Set 2012
A={'Pr1' 'P'
'Par2' 'PSO'
'Par3' 'MPSO'
'Par4' 'SOP'
'Par5' 'MPSO'
'Par6' 'SOPM'
'Par7' 'SOP'}
c=cellfun(@(x) sort(x),A(2:end,2),'uni',false)
d=unique(sort(c))
for k=1:numel(d)
B=A(2:end,:);
B=B(cellfun(@(x) all(ismember(x,d(k))),c),:)
n=size(B,1);
result=[A(1,:) ;B;{'total' , num2str(n)}]
out{k}=result
end
out{:}
0 Commenti
Vedere anche
Categorie
Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!