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

采纳的回答

Azzi Abdelmalek
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
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
kash
kash 2012-9-2
In fn{1,1}
'' 'c1' 'c2' 'c3'
'Par1' 'P' 'P' 'P'
'Par2' 'SPSO' 'PSO' 'MPSO'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'PSO' 'PSO' 'PSO'
PAr2,Par3 must be omitted because unique values in c1,c2,c3 are less than 2
'' 'c1' 'c2' 'c3' ''
'Par1' 'P' 'P' 'P' ''
'Par4' 'MPSO' 'MPSO' 'MPSO' 60
Par5' 'PSO' 'PSO' 'PSO' 60
in fn{2,1}
'' 'c1' 'c2' 'c3'
'Par2' 'S' 'S' 'S'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'SOP' 'PSO' 'SPO'
'Par3',must be omitted(only 2 unique values)
'' 'c1' 'c2' 'c3' ''
'Par2' 'S' 'S' 'S' ''
'Par4' 'MPSO' 'MPSO' 'MPSO' 60
'Par5' 'SOP' 'PSO' 'SPO' 60
but not getting results like this,please provide assistance

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
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 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2012-9-3
编辑:Azzi Abdelmalek 2012-9-3
i changed the code, is still there a problem?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by