vectorization and matlab functions for multiple for loops and conditionals within

1 visualización (últimos 30 días)
I want my code to run faster and this section seems like its making the code run slower.
I tried to vectorize it and use meshgrid but couldn't figure it out.
%linkswithpackets in node matrix form
l=1;
packets=zeros(N,N);
for m=1:N
for n=1:N
packets(m,n)=linkswithpacket(l);
l=l+1;
end
end
%generate all noma node combinations with packets
combinations_withpackets=[];
for i=1:N
for j=1:N
if(i~=j)
for k=1:N
if((k~=i)&&(k~=j))
if((packets(i,j)>0)&&(packets(i,k)>0))
combinations_withpackets=[combinations_withpackets;i j k];
end
end
end
end
end
end
This is supposed to create an array of the form [i j k] where i and j and k are nodes and at each row of the array they are not equal to each other. It adds an [i j k] combination to combinations_withpackets if there are packets from node i to j and node i to k.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by