calculating the percentage for unique values
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2012-9-1
编辑:Azzi Abdelmalek
2012-9-2
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 个评论
Azzi Abdelmalek
2012-9-2
编辑:Azzi Abdelmalek
2012-9-2
nr is the length of your array result
result =
{6x4 cell}
{5x4 cell}
{4x4 cell}
{3x3 cell}
in this case nr=4
更多回答(1 个)
Azzi Abdelmalek
2012-9-2
编辑:Azzi Abdelmalek
2012-9-3
% 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!