program that calls itself

15 vues (au cours des 30 derniers jours)
Oluwa KuIse
Oluwa KuIse le 20 Fév 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.

Réponse acceptée

Andrew Newell
Andrew Newell le 20 Fév 2012

Plus de réponses (1)

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

Catégories

En savoir plus sur Adding custom doc dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by