Combining data from other variable

19 ビュー (過去 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 Center および File ExchangeParticle Swarm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by