What you are doing here is probably a design issue that you may be able to resolve differently. Prompting for a parameter/option deep inside the call hierarchy seems wrong. To answer your question anyways, you could make that parameter, let's call it the multiplier f
, a persistent
variable of that inner function:
function c = dosomething(a, b)
persistent f;
while isempty(f)
f = input('enter multiplier: ');
end
c = f * a + b;
In the example, f
will be empty []
the first time dosomething
is called. In that case, the user will be prompted to enter a value. In subsequent calls, f
will still have this value (due to the declarator persistent
), and the user will not be prompted again.
A much better solution may be to have the outer function pass the parameter to dosomething(a, b, f);
, so the outer function may be the one that prompts the user.