Prev: mexMakeMemoryPersistent with mxRealloc
Next: Inverse evaluation - Give x value and get back the y value
From: Jack on 15 Jul 2010 19:53 Hi; I have the following representation of a graph in a form of Adjacenct List: 0 1 2 19 20 21 1 0 3 9 10 2 0 14 3 1 4 5 6 .. .. .. which means for the first row, the node 0 is connected to node 1 and node 2..etc I want to find all possible nodes in the graph and list them in an nx3 matrix. So for the first row the possible turns are [1 0 2; 1 0 19; 1 0 20; 1 0 21; 2 0 19; 2 0 20; 2 0 21;19 0 20; 19 0 21; 20 0 21] so the number of different turns for the first node will be (5 chose 2= 10). Many thanks
From: Bruno Luong on 16 Jul 2010 02:41 "Jack " <jack_sama_1981(a)yahoo.com> wrote in message <i1o710$mlh$1(a)fred.mathworks.com>... > Hi; > I have the following representation of a graph in a form of Adjacenct List: > 0 1 2 19 20 21 > 1 0 3 9 10 > 2 0 14 > 3 1 4 5 6 > . > . > . > which means for the first row, the node 0 is connected to node 1 and node 2..etc > I want to find all possible nodes in the graph and list them in an nx3 matrix. So for the first row the possible turns are [1 0 2; 1 0 19; 1 0 20; 1 0 21; 2 0 19; 2 0 20; 2 0 21;19 0 20; 19 0 21; 20 0 21] so the number of different turns for the first node will be (5 chose 2= 10). > help NCHOOSEK Bruno
From: Jack on 16 Jul 2010 13:10
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i1ouu2$m8j$1(a)fred.mathworks.com>... > "Jack " <jack_sama_1981(a)yahoo.com> wrote in message <i1o710$mlh$1(a)fred.mathworks.com>... > > Hi; > > I have the following representation of a graph in a form of Adjacenct List: > > 0 1 2 19 20 21 > > 1 0 3 9 10 > > 2 0 14 > > 3 1 4 5 6 > > . > > . > > . > > which means for the first row, the node 0 is connected to node 1 and node 2..etc > > I want to find all possible nodes in the graph and list them in an nx3 matrix. So for the first row the possible turns are [1 0 2; 1 0 19; 1 0 20; 1 0 21; 2 0 19; 2 0 20; 2 0 21;19 0 20; 19 0 21; 20 0 21] so the number of different turns for the first node will be (5 chose 2= 10). > > > > help NCHOOSEK > > Bruno thanks for the advice; I used the following code but is there a faster way? S = 0 1 2 3 4 1 0 2 4 NaN 2 0 1 3 NaN 3 0 2 4 NaN 4 0 1 3 NaN a= size (S); comb=[]; for i=1:a(1) A=S(i,:) A(1)=[]; B= nchoosek (A,2); C=[]; C(:,1)=B(:,1); C(:,2)=S(i,1); C(:,3)=B(:,2); comb=[comb;C] end D=[]; D=comb(:,1); index=find(isnan(D)) comb(index,:)=[]; D=comb(:,3); index=find(isnan(D)); comb(index,:)=[] thanks |