Re: Help needed: Macro to save plot profile data as text

Posted by Herbie-4 on
URL: http://imagej.273.s1.nabble.com/Help-needed-Macro-to-save-plot-profile-data-as-text-tp5012614p5012621.html

Dear ImageJ macro-coders,

ImageJ comes with an enormous amount of useful example code. However,
for many problems there exist various solutions and some are more
obvious than others...

In the here discussed situation one may follow an approach involving the
results table but the following appears more lucid and flexible, at
least to me:


Plot.getValues( x, y );
str = "X\tY\n"; // header
for ( i=0; i<x.length; i++ ) {
        str += "" + x[i] + "\t" + y[i] + "\n"; }
File.saveString( str, getDirectory( "imagej" ) + "/profileData.txt" );


Instead of x[i] and y[i] one may use d2s( x[i], d ) and d2s( y[i], d ),
with d denoting the number of decimal digits.

Happy coding

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::
Am 27.04.15 um 10:04 schrieb Peterbauer Thomas:

> On 2015-04-26 23:56, Silas Kraus wrote:
>> I already got help from another ImageJ user who sent me a link to a
>> very similar example macro that worked for me:
>> http://rsb.info.nih.gov/ij/macros/GetProfileExample.txt
>
>>> You are trying to save the plot, not the values. You have to get
>>> the values into a results table:
>>>
>>> run("Clear Results"); profile = getProfile(); for (i=0;
>>> i<profile.length; i++) { setResult("Value", i, profile[i]); }
>>> updateResults; saveAs("results","/path/to/file");
>>>
>
>> The strange thing is that this code still threw the same error. It
>> only differs from the above mentioned example macro in one line:
>> The "updateResults;" command is outside of the loop. When I put it
>> inside the loop, everything works fine.
>
> I cannot reproduce the error, neither with my code nor with the
> example macro. In the example macro, the "updateResults" command
> resides also outside the loop. There are just no curly brackets
> surrounding the "setResults" command, which means that only the first
> line following the for-statement (again only "setResults") is
> executed within the loop.

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