Why my code is very slow?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2022 年 8 月 2 日
Do not expect people to analyze your code in detail to figure out what it is intended to do and then invent better ways of doing it. You should document the purpose of the code, and have comments about how the code achieves the purpose.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Systems of Nonlinear Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!