program that calls itself

7 views (last 30 days)
Oluwa KuIse
Oluwa KuIse on 20 Feb 2012
How do I write a function file that calls itself without getting stuck in an infinite loop? I just want the program to call itself once.

Accepted Answer

Andrew Newell
Andrew Newell on 20 Feb 2012

More Answers (1)

Walter Roberson
Walter Roberson on 20 Feb 2012
Very simple example:
function x = foo(a,b)
if ~exist('b','var'); x = foo(a,0); return; end
x = a + b;
end

Categories

Find more on Argument Definitions in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!