Using the Results Table in a Loop

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

Using the Results Table in a Loop

Walsh, K. (Katherine)
Hi All,
I need to create a 'do while' loop in my macro but I need imagej to read the results table for the while clause
Eg.
Do {....}

While (%Area <3);

If that makes sense?
Thanks

Katherine Walsh


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

Re: Using the Results Table in a Loop

dscho
Hi Katherine,

On Thu, 7 Jun 2012, Walsh, K. (Katherine) wrote:

> I need to create a 'do while' loop in my macro but I need imagej to read
> the results table for the while clause
> Eg.
> Do {....}
>
> While (%Area <3);

You would run a row counter in a 'for' loop:

        for (row = 0; row <= nResults && getResult("Area", row) < 3; row++) {
                // Do your thing
        }

Compare also http://imagej.nih.gov/ij/developer/macro/macros.html#loops
and http://imagej.nih.gov/ij/developer/macro/macros.html#operators

By the way, this loop still might not do what you want, because the rows
are not necessarily ordered in ascending order of Area. If you need to
access the rows whose Area is smaller than 3, do something like this:

        for (row = 0; row <= nResults; row++) {
                if (getResult("Area", row) < 3) {
                        // Do your thing
                }
        }

Ciao,
Johannes

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