# Why my code is very slow?

4 views (last 30 days)

Show older comments

hello,

Can anybody optimize my code to be faster.

It is very slowly, in addition to that the network I used is very large.

I badly need to optimize it. My code include whil and several for that is why it is slow, and I does not know how upgrade it.

Thanks in advance

function diff =IC_realdata1(node)

s1=xlsread('d:\retweet.csv');

s2=s1(1:1000,:);

uu=unique(s2(:,2));

% vec(:,1)=(1:length(uu));

% vec(:,2)=uu;

g=dlmread('d:\sample\rel1.txt');

g=g(1:1000,:);

a0=node;%randi(length(uu),1);

T=false;

a1=a0;

b=a0;neb2=[];

while ~ T

neb1=[];

for i=1:length(b)

y=g(b(i),:);

nb=y(y~=0);

neb=[];

kk=1;

for j=1:length(nb)

idx=find(uu==nb(j));%% to be sure if distination within source

if ~isempty(idx)

neb(kk)=idx; %vec(idx,1);

kk=kk+1;

end

end

if ~isempty(neb)

neb1=[neb1 neb];

for k=1:length(neb)

r=ismember (neb(k),a1);

if r==1

neb1(neb1==neb(k))=[];

end

end

neb2= [neb2 neb1];

else

neb2=[];

end

end

neb=neb2;

neb=unique(neb);

for j=1:length(a0)

neb(neb==a0(j))=[];

end

b=neb1;

a1=union(a1,b);

if isempty(b)

T= true;

end

end

diff=a1;

##### 2 Comments

Walter Roberson
on 2 Aug 2022

### Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!