A nested function cannot be defined inside a control statement
(if
, while
, for
,
switch
or try/catch
).
Be aware that in addition to this message, other messages might appear in the
file. Such as, <control statement>
might not be aligned with its matching END
and Parse
error at END: usage might be invalid MATLAB syntax
. When you
remove the nested function definition from the control statement, these other
messages might disappear.
Rewrite the code so that a function is not defined within a control statement. For example, rewrite code such as this:
function foo(n)
while n > 10
function fs
disp('n is greater than 10')
end
n = n-1;
end
end
like this:
function foo(n)
while n > 10
fs
n = n-1;
end
function fs
disp('n is greater than 10')
end
end
For more information, see Nested Functions.