Login  Register

Re: Print a string to a custom table

Posted by Rasband, Wayne (NIH/NIMH) [E] on Jun 07, 2014; 6:17pm
URL: http://imagej.273.s1.nabble.com/Print-a-string-to-a-custom-table-tp5008085p5008087.html

On Jun 7, 2014, at 1:07 PM, Matt Pearson wrote:

> Hi all,
>
> How can I print a string to rows of a custom made table?  When i try to do it, it inputs zeros instead, it works fine for numbers.  Also if i used the Results table how do you use getResult() with strings, i keep getting NaN.

Use setResult(column,row,string) to add strings to the results table and getResultString(column,row) to retrieve them. The following example creates a results table, adds a string to each row in the table, and then retrieves and prints the strings.

-wayne

  run("T1 Head (2.4M, 16-bits)");
  for (i=1; i<=nSlices; i++) {
     setSlice(i);
     run("Measure");
  }
  for (i=0; i<nResults; i++)
     setResult("Name", i, "name"+IJ.pad(i+1,3));
  updateResults;
  for (i=0; i<nResults; i++)
     print(i, getResultString("Name", i));


> Thanks,
>
> Matt
>
> //Create overall results table
> title1 = "Overall Results";
> title2 = "["+title1+"]";
> f = title2;
> if (isOpen(title1)) {}
> else {
> run("Table...", "name="+title2+" width=1800 height=600");
> //Table headings
> print(f, "\\Headings:Measurement\tName\tDistance");
> }
> image_name = "1 25.ome.tiff";
>
> Measurement = 0;
> Distance = 0;
> Name = image_name;
> for (i=0; i<nResults(); i++){
> Measurement = i+1;
> Distance = (getResult("Distance", i));
>
> print(f,(Measurement)+"\t"+(Name)+"\t"+(Distance));
>
> }
>
>
> --
> 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