For loops not executed

Q&ACategory: BugFor loops not executed
Admin Staff asked 2 years ago

I’m calculating the mutual information between two images, however for some reason the code in a double for loop is not executed

function [s:scalar] = MI3(im1:mat,im2:mat,nbins:scalar)

nsamples=numel(im1)
h1 = imhist(im1,linspace(0,255,nbins))
h2 = imhist(im2,linspace(0,255,nbins))
jointh = imjointhist(im1,im2,linspace(0,255,nbins),linspace(0,255,nbins))

jointh=jointh/nsamples

assert(type(h1,"vec"))
assert(type(h2,"vec"))
h1=h1/nsamples
h2=h2/nsamples

binsize=size(im1,1);
mi=0
for cntx=0..size(jointh,0)%[0]-1
for cnty=0..size(jointh,1)%[1]-1
print("bla")
if(jointh[cntx,cnty] != 0 &&(h1[cntx]*h2[cnty])!=0)
mi+=jointh[cntx,cnty]*log10(binsize*jointh[cntx,cnty]/(h1[cntx]*h2[cnty]))
endif
end
end

s=mi/binsize
end
2 Answers
bgoossen Staff answered 2 years ago

mi is an integer, so that all accumulation operations have no effect. If you define as mi = 0.0, there should be a non-zero result for s.
“bla” is printed from within a kernel, normally the result should be visible in the console. In windows it is handled correctly. In linux the result may be buffered. Will check.

Admin Staff answered 2 years ago

By changing mi to 0.0 I do get a different solution, however the printing does not show in the immediate window, as I would expect it would. 
Part of my confusion is probably also due to the fact that my breakpoints in the loop are ignored by the debugger. If you want to do this by design, i would advise to place the red dot (breakpoint) at at the end of the for loop. But I seem to remember that normally quasar was able to debug parallellized for loops (true simulation)?