MATLAB: Errors in Menu program

Hi all,
I'm a newbie to Matlab and wrote a program using menu as follows:
*eapplication.m*
choice = eoption;
while choice ~= 4
switch choice
case 1
explaine;
case 2
limite;
case 3
x = input('Please enter a value for x: ');
expfn(x);
end
choice = eoption;
end
*eoption.m*
choice = menu('Choose an e option', 'Explanation', 'Limit', … 'Exponential function', 'Exit Program');
while choice == 0
disp('Error – please choose one option.')
choice = menu('Choose an e option', 'Explanation', 'Limit', … 'Exponential function', 'Exit Program'); end
*It gave me an error: ??? Attempt to execute SCRIPT eoption as a function: C:\Documents and Settings\Olive\My Documents\MATLAB\eoption.m
Error in ==> eapplication at 1 choice = eoption;*
Could you please shed some lights?
Thanks heaps.
Oliver.

Best Answer

Pretty much what it says. The line choice = eoption; implies that eoption is a function call (because it is asking for an output, to be assigned to choice). But eoption is a script, not a function.
The difference is in how variables are managed. Scripts work with the base MATLAB workspace. Functions use local workspaces, so variables are local. So your options are:
  1. Turn eoption into a function by adding the line function choice = eoption at the beginning.
  2. Leave eoption as a script and inherit choice from the base workspace. Hence, change the line choice = eoption; (in eapplication) to just eoption;
Related Question