Info

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

how can i minimize this loop timing please suggest.....

1 view (last 30 days)
chirag
chirag on 28 Aug 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
window=100;
wi=(window-1)/2;
temp2=0;
for k=0:row-window
for l=0:col-window
for i=1:window
for j=1:window
temp1(i,j)=double(l1(i+k,j+l));
end
end
LocalMean=mean(mean(temp1));
% LocalVar=var(var(temp1));
for i=1:window
for j=1:window
temp2=temp2+(temp1(i,j)-LocalMean)^2;
end
end
temp3(k+wi,l+wi)=temp2/(101^2);
temp2=0;
end
end
[EDITED, Jan, code formatted]

Answers (1)

Jan
Jan on 28 Aug 2012
Edited: Jan on 28 Aug 2012
window = 100;
wi = ceil((window-1)/2); % CEIL is required!
c1 = 101 ^ 2;
temp3 = zeros(row - window + wi); % Pre-allocate!!!
for k = 0:row-window
for l = 0:col-window
temp1 = double(l1(1+k:window+k, 1+l:window+l);
LocalMean = sum(temp1(:)) / numel(temp1);
kk = temp1(:) - LocalMean;
temp3(k+wi,l+wi) = (kk' * kk) / c;
end
end
wi = (window-1)/2 is not an integer for window = 100. You need CEIL,m FLOOR or ROUND.

Community Treasure Hunt

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

Start Hunting!