Combining data from other variable
20 views (last 30 days)
Show older comments
I have two variables names ad below
Parameters={
'' 'c1' 'c2' 'c3'
Par1 'PSO' 'SPSO' 'MPSO'
Par2 'SPSO' 'PSO' 'MPSO'
Par3 'MPSO' 'PSO' 'PSO'
Par4 'MPSO' 'MPSO' 'MPSO'
Par5 'SPSO' 'PSO' 'PSO' }
Variables={
'' c1' 'c2' 'c3'
Par1 'P' 'P' 'P'
Par2 'S' 'S' 'S'
Par3 'M' 'M' 'M'
Par4 'P' 'S' 'S'
Par5 'S' 'M' 'M'}
I have seen some posts posted by Pat,but i could not get the following result, I want to combine variables as shown below ,please help
Result{1,1}
'' c1' 'c2' 'c3'
Par1 'P' 'P' 'P'
Par2 'SPSO' 'PSO' 'MPSO'
par3 'MPSO' 'PSO' 'PSO'
Par4 'MPSO' 'MPSO' 'MPSO'
Par5 'SPSO' 'PSO' 'PSO'
Result{2,1}
Par2 'S' 'S' 'S'
Par3 'MPSO' 'PSO' 'PSO'
Par4 'MPSO' 'MPSO' 'MPSO'
Par5 'SPSO' 'PSO' 'PSO'
Result{3,1}
Par3 'M' 'M' 'M'
Par4 'MPSO' 'MPSO' 'MPSO'
Par5 'SPSO' 'PSO' 'PSO'
Result{4,1}
Par4 'P' 'S' 'S'
Par5 'SPSO' 'PSO' 'PSO'
please provide assistance
0 Comments
Accepted Answer
Andrei Bobrov
on 27 Aug 2012
Edited: Andrei Bobrov
on 27 Aug 2012
P={
'' 'c1' 'c2' 'c3'
'Par1' 'PSO' 'SPSO' 'MPSO'
'Par2' 'SPSO' 'PSO' 'MPSO'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'SPSO' 'PSO' 'PSO' };
V={
'' 'c1' 'c2' 'c3'
'Par1' 'P' 'P' 'P'
'Par2' 'S' 'S' 'S'
'Par3' 'M' 'M' 'M'
'Par4' 'P' 'S' 'S'
'Par5' 'S' 'M' 'M'};
R = cell(size(P,1)-2,1);
for jj = 1:numel(R)
R{jj} = [V(1,:);V(jj+1,:);P(jj+2:end,:)];
end
OR
X = num2cell(V(2:end-1,:),2);
Y = num2cell(triu(ones(size(P,1)-[2 0]),2) > 0,2);
R = cellfun(@(x,y)[P(1,:);x;P(y,:)],X,Y,'un',0);
3 Comments
Walter Roberson
on 27 Aug 2012
I could not tell which part of that were meant literally and which parts were intended to be text.
More Answers (0)
See Also
Categories
Find more on Particle Swarm 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!