MATLAB: Subscript indices must either be real positive integers or logicals.

faqimageindex

Hi,
dist = sqrt((r1 - r2) ^ 2 + (c1 - c2) ^ 2);
costs(i) = 1 /ceil( dist) * exp(- abs(ceil(img(abs(r1), abs(c1))) - ceil(img(abs(r2),abs(c2)))) ^ 2 / (2 * sigma ^ 2));
c2 is equal to 0 ,so it returns Subscript indices must either be real positive integers or logicals.
Thanks