Login  Register

Re: getResult to Array gives NaN

Posted by Michael Schmid on Oct 24, 2016; 4:38pm
URL: http://imagej.273.s1.nabble.com/getResult-to-Array-gives-NaN-tp5017460p5017464.html

Hi Herbie & Matt,

funny enough, the ImageJ macro language does support mixed arrays,
having Strings and numbers (internally, both are type 'Variable'). E.g.,
the following macro works:

   a = newArray(1, "theString", PI);
   for (i=0; i<a.length; i++)
   print(a[i]);

However, the getResult macro function is for numeric values only. If
there is a String argument, it tries to interpret the string contents as
a number (parse the String).

You have to use getResultString for Strings.

If you don't know beforehand whether it is a number or a string, you can
try getResult, and, if it returns NaN, use getResultString.

Michael
________________________________________________________________
On 2016-10-24 17:36, Herbie wrote:
 > Good day Matt,
 >
 > you can't have strings and numerical values in the same array.
 >
 > Therefore, you may convert the values to strings to end up with a pure
 > string array. If you like to read the values back from the string array,
 > you have to convert them from strings to numbers.
 >
 > HTH
 >
 > Herbie
 >
 > :::::::::::::::::::::::::::::::::::::::::::::
 > Am 24.10.16 um 17:22 schrieb PEARSON Matthew:
 >> Hi all,
 >>
 >> I'm having a bit of an issue with taking values from the results
 >> table and putting them into an array.  The first column of the
 >> results table contains a string, the current images title stored as a
 >> variable such as "test.tif" all other columns contain numbers.  The
 >> results table displays fine but when i loop through using getResult
 >> to put all the table values into an array, when i print the resultant
 >> array (Array.print) the values from the first column containing
 >> strings are listed as NaN.  How can i correct this?  Ultimately when
 >> i use this array to produce the final results table the first column
 >> is then filled with NaN.
 >>
 >> Thanks for the help,
 >>
 >> Matt
 >>
 >>
 >> -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute
 >> of Genetics and Molecular Medicine (IGMM) University of Edinburgh
 >> Crewe Road EH4 2XU
 >>
 >>
 >>
 >>
 >>
 >> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
 >>
 >>
 >>
 >> The University of Edinburgh is a charitable body, registered in
 >> Scotland, with registration number SC005336.
 >>
 >> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
 >>
 >
 > --
 > ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html