Combining data from other variable

20 views (last 30 days)
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

Accepted Answer

Andrei Bobrov
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
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.
kash
kash on 27 Aug 2012
In variable editor for R{1,1}i get as
'' 'c1' 'c2' 'c3'
'Par1' 'P' 'P' 'P'
'Par2' 'SPSO' 'PSO' 'MPSO'
'Par3' 'MPSO' 'PSO' 'PSO'
'Par4' 'MPSO' 'MPSO' 'MPSO'
'Par5' 'SPSO' 'PSO' 'PSO'
but in command window i want to display with bracket and commas as
(stating as, if parameter in column 1 is P ,wat the other parameters represents)
C1--->Par1(P)--->Par2(SPSO),Par3(MPSO),Par4(MPSO),Par5(SPSO)
C2--->Par1(P)---->Par2(PSO),Par3(PSO),Par4(MPSO),Par5(PSO)
same for c3
is it possible to display like above for R{2,1},R{3,1},R{4,1}

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!