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:
how to query the current "recursion" level?

Subject: how to query the current "recursion" level?

From: carlos lopez

Date: 13 Aug, 2009 00:19:03

Message: 1 of 5

Hello:
I am getting some "recursion limit" error messages, and I want to catch such situation by asking the current "recursion level" (i.e. a number which increments by one for every recursive self-call).
Is it available somewhere? Could you please state how to query it?
Regards
Carlos

Subject: how to query the current "recursion" level?

From: Jan Simon

Date: 13 Aug, 2009 01:10:18

Message: 2 of 5

Dear Carlos!

> I am getting some "recursion limit" error messages, and I want to catch such situation by asking the current "recursion level" (i.e. a number which increments by one for every recursive self-call).
> Is it available somewhere? Could you please state how to query it?

The reply of DBSTACK contains a list of calling processes, so the recursion depth can be obtained.

Good luck, Jan

Subject: how to query the current "recursion" level?

From: carlos lopez

Date: 13 Aug, 2009 11:58:02

Message: 3 of 5

Thank you a lot, Jan!
Carlos

Subject: how to query the current "recursion" level?

From: Rune Allnor

Date: 13 Aug, 2009 12:10:10

Message: 4 of 5

On 13 Aug, 02:19, "carlos lopez" <clv2clv_000000...@adinet.com.uy>
wrote:
> Hello:
> I am getting some "recursion limit"  error messages, and I want to catch such situation by asking the current "recursion level"  (i.e. a number which increments by one for every recursive self-call).

Use another argument to your recursive function:

function myFunction(x,level)
   if level>0
        myFunction(x,level-1);
   end
end

This way you call the function with the allowed level
of recursions.

Apart from that, if your function keeps hitting the
limits for the recursion levels, the cause is usually
that your termination criteria are ill-posed. Make sure
you know exactly what you are doing.

Rune

Subject: how to query the current "recursion" level?

From: carlos lopez

Date: 13 Aug, 2009 13:39:02

Message: 5 of 5

Rune Allnor <allnor@tele.ntnu.no> wrote in message
> Apart from that, if your function keeps hitting the
> limits for the recursion levels, the cause is usually
> that your termination criteria are ill-posed. Make sure
> you know exactly what you are doing.
Hello Rune:
Thank you for your comments. At normal operation the routine should not attain any recursion limit. The problem is that, while developing the routine, I need to process a somewhat large AutoDesk DXF file and "somewhere" after processing an unknown bunch of information the routine recurses. I am trying to catch where it happends, and maybe discover why. I hope that by asking here and there about the recursion level I will be able to stop processing and check the input data for that case. So, at this very moment, I do not know why and where it recurses up to the limit.
Regards, and thank you again for the advice
Carlos

Tags for 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