calculating the percentage for unique values
1 view (last 30 days)
Show older comments
I have values
result =
{6x4 cell}
{5x4 cell}
{4x4 cell}
{3x3 cell}
'' 'c1' 'c2' 'c3'
'Par1' 'P' 'P' 'P'
'Par2' 'SPSO' 'PSO' 'MPSO'
'Par3' 'PSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'SPSO' 'PSO' 'PSO'
In result{1,1} i have
'' 'c1' 'c2' 'c3'
'Par1' 'P' 'P' 'P'
'Par2' 'SPSO' 'PSO' 'MPSO'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'PSO' 'SPO' 'PSO'
in par2 all values in 3 columns are different so it must be omitted
in par3 there are 3 numbers of PSO so the percentage is 60(3/5*100)
in par4 there are 3 numbers of MPSO so the percentage is 60(3/5*100)
in par5 there a are 3 numbers of PSO(PSO is same as SPO OR POS) so the percentage is 60(3/5*100)
SAME WAY MPSO is same as PSOMor combination of these four words
please tell how to process
0 Comments
Accepted Answer
Azzi Abdelmalek
on 1 Sep 2012
Edited: Azzi Abdelmalek
on 2 Sep 2012
nr=size(result,1)
for k=1:nr
A=result{k};
[n,m]=size(A)
for i1=2:n
test(i1-1)=1
p=perms(char(A(i1,2)))
for j1=3:m
test(i1-1)=and(min(min(ismember(p,char(A(i1,j1))))),test(i1-1));
end
end
perc{k}=[100*(m-1)/(n-1)*test]'
end
3 Comments
Azzi Abdelmalek
on 2 Sep 2012
Edited: Azzi Abdelmalek
on 2 Sep 2012
nr is the length of your array result
result =
{6x4 cell}
{5x4 cell}
{4x4 cell}
{3x3 cell}
in this case nr=4
More Answers (1)
Azzi Abdelmalek
on 2 Sep 2012
Edited: Azzi Abdelmalek
on 3 Sep 2012
% updated code
clear;clc
result={{'' 'c1' 'c2' 'c3'
'Par1' 'P' 'P' 'P'
'Par2' 'SPSO' 'PSO' 'MPSO'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'PSO' 'PSO' 'PSO'},
{'' 'c1' 'c2' 'c3'
'Par2' 'S' 'S' 'S'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'SOP' 'PSO' 'SPO'}};
nr=size(result,1)
for k=1:nr
A=result{k};test=[];
[n,m]=size(A)
for i1=2:n
test(i1-1)=1
p=sort(char(A(i1,2)))
for j1=3:m
test(i1-1)=and(isequal(p,sort(char(A(i1,j1)))),test(i1-1))
end
end
perc=num2cell([100*(m-1)/5*test]');
A{1,m+1}='perc';
A(2:end,m+1)=perc;
test=[1 test];
A(test==0,:)=[]
result{k}=A
end
result{1},result{2}
6 Comments
Azzi Abdelmalek
on 3 Sep 2012
Edited: Azzi Abdelmalek
on 3 Sep 2012
i changed the code, is still there a problem?
See Also
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!