vectorization and matlab functions for multiple for loops and conditionals within

1 次查看(过去 30 天)
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by