Info

This question is closed. Reopen it to edit or answer.

can i speed up this code and get rid of nested for loop??

1 view (last 30 days)
%coeffs1 is n*3 matrix with unknown n,i have no idea about it through
processing%%
for k=1:length(coeffs1)
for i=1:length(unique(l))
[r2, c2]= find(l == i & pd<inf); % pd and l are matrices of 300*300
[r3, ~]=find(l==i & nc<inf); % nc is matrix of 300*300
if ~isempty(r2)
v=zeros(length(r2),1);
for n=1:length(r2)
v(n)=pd(r2(n),c2(n));
end
zbar=eval2dPoly(r2,c2,coeffs1(k,:)'); % Zbar is estimated new values using function eval2dPoly %%%%
m=abs(zbar-v);
r1=length(find(m==0));
if r1/ length(r3)>=0
lamda=10;%10
dc=lamda*m*exp(-r1/length(r3));
Dc(k,i)=sum(dc);
end
end
end
end
  6 Comments
Doaa Adel
Doaa Adel on 4 Jan 2015
thank you Geoff Hayes, i use profiler always, this part of code takes about 1600 seconds and that is so so long.
thank you per isakson, of course i did that but it is just not mentioned here
per isakson
per isakson on 4 Jan 2015
Edited: per isakson on 4 Jan 2015
It's difficult to help without running the code, which is difficult without input data.
What's make you believe that it is the for-loops, which cause the problem?

Answers (0)

Community Treasure Hunt

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

Start Hunting!