Hi everyone,
I am trying to grab the value of i for which out(i) is equal to s(2). The segment is marked below by '% facing problem here'. Correct value of d is the answer. Can anyone please help me to figure that out? thanks a lot.
function mainn = 6; long_min = 1.;lat_min = 1.;w = 2.;h = 1.;bound.xmin = long_min;bound.xmax = long_min + w;bound.ymin = lat_min;bound.ymax = lat_min + h;% generating the sample points
long = long_min + w * rand(1,n);lat = lat_min + h * rand(1,n); %structure arrays
pts = struct('num',{},'x',{},'y',{});for i=1:n pts(i).num=i; pts(i).x=long(i); pts(i).y=lat(i);enda = 5; for i = 1:n out(i) = near_pt(pts(i).x, pts(i).y, pts(a).x, pts(a).y) end% facing problem here
s = sort(out(:));if (out(i)== s(2)) d = [i]; % return the value of i for which out(i)== s(2)
end; disp(d);endfunction out = near_pt(p, q, r, s) out = sqrt((r - p)^2+(s - q)^2); end
Best Answer