getResult to Array gives NaN

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

getResult to Array gives NaN

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
Reply | Threaded
Open this post in threaded view
|

Re: getResult to Array gives NaN

Herbie
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
Reply | Threaded
Open this post in threaded view
|

Re: getResult to Array gives NaN

PEARSON Matthew
Hi Herbie,

I did wonder about this but yet i have an array earlier in my macro which stores only 2 values, the first is a string and the second a number.  Does this somehow indicate that specifically you cannot create an array of numbers and strings when extracting from the results table using getResult?

Thanks,

Matt

--
Matt Pearson
Microscopy Facility
MRC Human Genetics Unit
Institute of Genetics and Molecular Medicine (IGMM)
University of Edinburgh
Crewe Road
EH4 2XU




On 24 Oct 2016, at 16:36, Herbie <[hidden email]<mailto:[hidden email]>>
 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
Reply | Threaded
Open this post in threaded view
|

Re: getResult to Array gives NaN

Herbie
Matt,

perhaps the mentioned array is of the following type:

Run this little macro:
//////////////////////////
a = newArray("Just an Integer","1");
Array.show( a );
//////////////////////////

Just a guess

Herbie

:::::::::::::::::::::::::::::::::::::::::::::
Am 24.10.16 um 17:57 schrieb PEARSON Matthew:

> Hi Herbie,
>
> I did wonder about this but yet i have an array earlier in my macro
> which stores only 2 values, the first is a string and the second a
> number.  Does this somehow indicate that specifically you cannot
> create an array of numbers and strings when extracting from the
> results table using getResult?
>
> Thanks,
>
> Matt
>
> -- Matt Pearson Microscopy Facility MRC Human Genetics Unit Institute
> of Genetics and Molecular Medicine (IGMM) University of Edinburgh
> Crewe Road EH4 2XU
>
>
>
>
> On 24 Oct 2016, at 16:36, Herbie
> <[hidden email]<mailto:[hidden email]>> 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: getResult to Array gives NaN

Michael Schmid
In reply to this post by PEARSON Matthew
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
Reply | Threaded
Open this post in threaded view
|

Re: getResult to Array gives NaN

Herbie
Thank you Michael,

that's really funny.

The macro language again surprise me!

Good evening

Herbie

::::::::::::::::::::::::::::::::::::::::::::
Am 24.10.16 um 18:38 schrieb Michael Schmid:

> 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
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: getResult to Array gives NaN

PEARSON Matthew
In reply to this post by Michael Schmid
Hi Michael and Herbie,

Great, you learn something every day! I think I can work with this.

Thanks again,

Matt


-------- Original message --------
From: Michael Schmid <[hidden email]>
Date: 24/10/2016 17:40 (GMT+00:00)
To: [hidden email]
Subject: Re: getResult to Array gives NaN

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

--
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