Combining data from other variable

조회 수: 20 (최근 30일)
kash
kash 2012년 8월 27일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 8월 27일
편집: Andrei Bobrov 2012년 8월 27일
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
Walter Roberson
Walter Roberson 2012년 8월 27일
I could not tell which part of that were meant literally and which parts were intended to be text.
kash
kash 2012년 8월 27일
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}

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by