Login  Register

Re: Premature loop exit with "run(..." command

Posted by G. Esteban Fernandez on Jan 11, 2011; 4:40pm
URL: http://imagej.273.s1.nabble.com/Premature-loop-exit-with-run-command-tp3686030p3686032.html

Yes, it did have nSlices, thanks!  Next time I'll put the full code in my
post...

-Esteban

On Tue, Jan 11, 2011 at 1:25 AM, Michael Schmid <[hidden email]>wrote:

> Hi Esteban,
>
> does your for loop have nSlices in the terminating condition? Then it may
> terminate because nSlices=1 for the image created by "Z Project...", which
> becomes the foreground image.
>
> For example, this runs only once:
>
> for (i=1; i<=nSlices; i++) {
>  run("Z Project...", "start=1 stop=&i projection=[Average Intensity]");
>  // the output is foreground image, it has nSlices=1
>  rename("average_of_slices_1-"+i);
> }
>
> This does the full loop:
>
> originalID = getImageID();
> for (i=1; i<=nSlices; i++) {
>  run("Z Project...", "start=1 stop=&i projection=[Average Intensity]");
>  rename("average_of_slices_1-"+i);
>  selectImage(originalID);
> }
>
>
> Michael
> ________________________________________________________________
>
>
> On 10 Jan 2011, at 22:02, G. Esteban Fernandez wrote:
>
> Hi all,
>>
>> In a macro I have a "Z Project" command inside a FOR loop:
>>
>> for(){
>>     run("Z Project...", ...
>> }
>>
>> However the FOR loop exits prematurely after running its code only once
>> even
>> though the exit condition has not been met.  If I comment out the one
>> "run(..." line the loop runs the expected number of times.  Is it normal
>> behavior for loop code to run only once if it contains a "run(..."
>> statement? (this happens with WHILE too)
>>
>> Thanks,
>> Esteban
>>
>