Re: distance between adjacent particles
Posted by
jchanson on
May 10, 2007; 6:48pm
URL: http://imagej.273.s1.nabble.com/distance-between-adjacent-particles-tp3699485p3699491.html
France -
It looks like you initialize the value of "dist1" inside the for
loop where you're calculating all of the distances. You should just
initialize it to a large value outside of the for loop. Try this,
instead:
var dist1;
var dist;
for (i=0; i<nResults; i++) {
XM=getResult("XM", i);
YM=getResult("YM",i);
a=nResults;
a1 = newArray(a);
for (b=0; b<nResults; b++){
XM2=getResult("XM", b);
YM2=getResult("YM",b);
dist=sqrt(((XM2-XM)*(XM2-XM))+((YM2-YM)*(YM2-YM)));
a1[b] = dist;
}
dist1=10000;
for (b=0;b<a;b++){
dist=a1[b];
if(dist==0){dist=10000;}
if (dist>dist1)
{dist=dist1;}
dist1=dist;
}
print(dist1);
setResult("shortest_dist", i, dist1);
}
updateResults();
Jeff
Senior Imaging Analyst
[hidden email]