macro array value limit
Posted by Michael Doube-2 on
URL: http://imagej.273.s1.nabble.com/macro-array-value-limit-tp3701176.html
Dear List,
I've encountered a strange behaviour in a macro I'm writing.
I want to parse a comma-separated list of values and plot them in an
image. To scale the plot, I have to find the maximum value. So, I've
pushed the value into an array, and while doing so done an if loop to
reassign a 'max' value to the new, bigger value.
What happens is that in the if loop, values bigger than 9.99 and 9999
are ignored. The arrays do contain bigger values, but somehow they are
excluded from the 'if'. I can print out values bigger than 9.99 and 9999
(if I simply print the arrays as soon as they are parsed). This means
that when the true maximum of the array should be 11.38 (for example),
if I print my max (from the if loop) it is reported as 9.99.
ImageJ version 1.37r, Java 1.3.1_13, WinXP
Mike
----------
//Open the array file which must be a csv list in (angle, value \n) format
string = File.openAsString("");
//Split the CSV file into an array of lines
lines = split(string, "\n");
//initialise some variables
theta = newArray(lengthOf(lines));
r = newArray(lengthOf(lines));
rmax = 0;
//Put the csv into 2 arrays
//Find the maximum radius (to determine the outer boundary)
for (n=0; n<lengthOf(lines); n++){
thetar= split(lines[n], "\,");
theta[n] = thetar[0];
r[n] = thetar[1];
//check that the csv has been parsed properly
print(theta[n],r[n]);
//find the maximum value of r
if (r[n] > rmax){
rmax = r[n];
}
}
print(rmax);
--
Michael Doube BPhil BVSc MRCVS
PhD Student
Dental Institute
Queen Mary, University of London
New Rd
London E1 1BB
United Kingdom
Phone +44 (0)20 7377 7000 ext 2681