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. 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 |
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 |
H Wayne,
Thanks for that and for printing a string stored in a variable to a table other than results, i found that the variable needs a plus sign either side and a pair of double quotation marks either side, at least thats what worked for me.. Where "Name" is a string: print(f,(Measurement)+"\t"+" "+Name+" "+"\t"+(Distance)); Thanks, Matt On 7 Jun 2014, at 19:17, "Rasband, Wayne (NIH/NIMH) [E]" <[hidden email]> wrote: > 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 > -- 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 |
Free forum by Nabble | Edit this page |