2016-06-24 3 views
1

Ich habe eine Matrix W in Matlab der Dimension nx2 und ich möchte eine Liste von 2x1 Zellen in Zell 1 genommen eine mögliche Kombination von Reihen von Wk2 den linken Reihen von W zu einer Zeit und in Zelle Auflistung konstruieren.Zeilenkombinationen in Matlab?

Example: 

n=9; 

W=[0 1; 0 2; 0 3; 0 4; 0 5; 1 6; 2 6; 3 6]; 

k=1; 

W_1=[{[0 1]}; {[0 2; 0 3; 0 4; 0 5; 1 6; 2 6; 3 6]}]; 
W_2=[{[0 2]}; {[0 1; 0 3; 0 4; 0 5; 1 6; 2 6; 3 6]}]; 
W_3=[{[0 3]}; {[0 1; 0 2; 0 4; 0 5; 1 6; 2 6; 3 6]}]; 
W_4=[{[0 4]}; {[0 1; 0 2; 0 3; 0 5; 1 6; 2 6; 3 6]}]; 
W_5=[{[0 5]}; {[0 1; 0 2; 0 3; 0 4; 1 6; 2 6; 3 6]}]; 
W_6=[{[1 6]}; {[0 1; 0 2; 0 3; 0 4; 0 5; 2 6; 3 6]}]; 
W_7=[{[2 6]}; {[0 1; 0 2; 0 3; 0 4; 0 5; 1 6; 3 6]}]; 
W_8=[{[3 6]}; {[0 1; 0 2; 0 3; 0 4; 0 5; 1 6; 2 6]}]; 

Antwort

0

versuchen, diese Methode

cell1 = {}; 
W=[0 1; 0 2; 0 3; 0 4; 0 5; 1 6; 2 6; 3 6]; 
b = (1:size(W,1)).' 
for i= 1:size(W,1) 
    cell1{end +1}= [ {W(ismember(b,i),:)}, {W(~ismember(b,i),:)}] 
end 
cell1 = 

    {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} 

>> cell1{1, 2}{1,1} 

ans = 

0  2 

>> cell1{1, 2}{1,2} 

ans = 

    0  1 
    0  3 
    0  4 
    0  5 
    1  6 
    2  6 
    3  6