Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Returning within a Number of Functions

Subject: Returning within a Number of Functions

From: LindsE

Date: 10 Sep, 2008 17:22:13

Message: 1 of 3

Hi there;

I have a series of several functions running within a large loop and
would like Matlab to proceed to the next value in the loop if a
certain condition exists.

For example:


I run a calling function that calls about 15 - 20 other functions
within a loop (111 iterations). Within function #12, if a variable =
0, I want Matlab to stop the iteration and return to the calling
function taking the next iteration and running until the condition is
met again.

Is there a function that can do this? Right now I'm using:
        warning('Required data may be out of grid''s bounds')
        dbstop if warning

but that won't allow the function to continue with the next
iteration. Is it possible to use a "try"/"catch" such that
try

Subject: Returning within a Number of Functions

From: Yuri Geshelin

Date: 10 Sep, 2008 18:05:18

Message: 2 of 3

Hi,

In this writing, I assume that by "iteration" you mean a pass of the loop, not call(s) to one of the 15-20 functions.

Let *flag* be an output argument of function #12:

[........, flag, ......] = function_12(...)

Next, write the following in the body of function_12:

if variable==0, flag = -98989; return, end

(Also don't forget to assign a different value to 'flag' if variable is not zero).

Once variable==0, function_12 will terminate, and the loop will continue.

Immediately after the call to function_12, write this:

if flag == -98989, continue, end

This will skip the rest of the loop, and the next iteration will start.

Yuri

LindsE <LindsEHillier@gmail.com> wrote in message <110f6c3c-dfd9-43c5-97d8-3dae743c831e@25g2000hsx.googlegroups.com>...
> Hi there;
>
> I have a series of several functions running within a large loop and
> would like Matlab to proceed to the next value in the loop if a
> certain condition exists.
>
> For example:
>
>
> I run a calling function that calls about 15 - 20 other functions
> within a loop (111 iterations). Within function #12, if a variable =
> 0, I want Matlab to stop the iteration and return to the calling
> function taking the next iteration and running until the condition is
> met again.
>
> Is there a function that can do this? Right now I'm using:
> warning('Required data may be out of grid''s bounds')
> dbstop if warning
>
> but that won't allow the function to continue with the next
> iteration. Is it possible to use a "try"/"catch" such that
> try

Subject: Returning within a Number of Functions

From: LindsE

Date: 10 Sep, 2008 18:09:56

Message: 3 of 3

On Sep 10, 4:05=A0pm, "Yuri Geshelin" <geshe...@hotmail.com> wrote:
> Hi,
>
> In this writing, I assume that by "iteration" you mean a pass of the loop=
, not call(s) to one of the 15-20 functions.
>
> Let *flag* be an output argument of function #12:
>
> [........, flag, ......] =3D function_12(...)
>
> Next, write the following in the body of function_12:
>
> if variable=3D=3D0, flag =3D -98989; return, end
>
> (Also don't forget to assign a different value to 'flag' if variable is n=
ot zero).
>
> Once variable=3D=3D0, function_12 will terminate, and the loop will conti=
nue.
>
> Immediately after the call to function_12, write this:
>
> if flag =3D=3D -98989, continue, end
>
> This will skip the rest of the loop, and the next iteration will start.
>
> Yuri
>
> LindsE <LindsEHill...@gmail.com> wrote in message <110f6c3c-dfd9-43c5-97d=
8-3dae743c8...@25g2000hsx.googlegroups.com>...
> > Hi there;
>
> > I have a series of several functions running within a large loop and
> > would like Matlab to proceed to the next value in the loop if a
> > certain condition exists.
>
> > For example:
>
> > I run a calling function that calls about 15 - 20 other functions
> > within a loop (111 iterations). Within function #12, if a variable =3D
> > 0, I want Matlab to stop the iteration and return to the calling
> > function taking the next iteration and running until the condition is
> > met again.
>
> > Is there a function that can do this? Right now I'm using:
> > =A0 =A0 =A0 =A0 warning('Required data may be out of grid''s bounds')
> > =A0 =A0 =A0 =A0 dbstop if warning
>
> > but that won't allow the function to continue with the next
> > iteration. =A0Is it possible to use a "try"/"catch" such that
> > try

Very clever! Thank you so much! That'll work like a charm.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us