MATLAB enforces a nesting limit of 15 for functions. This message appears when one or more of the following is true:
Some of the functions in the file are written with
end
statements and others are not.
When Code Analyzer examines the file, it checks to see if functions
terminate with end
statements. If the functions are
not nested, you can omit their corresponding end
statements. However, the same file cannot have some functions with
end
statements and some without.
There is an extra end
statement in the file and it
appears to Code Analyzer that it matches a function
keyword.
For example, suppose your code has nested for
loops
and multiple unnested functions without end
statements. Furthermore, suppose there is an extra
end
statement for one of the
for
loops. If that end
statement appears to match a function keyword, Code Analyzer interprets
it as the situation described in the first item in this list.
Functions with end
statements are nested more than
15 deep.
In the first two cases, additional messages might indicate where the extra
end
is. Code Analyzer indicates keywords that do not
align with their matching end
keywords.
If the message is due to mixing function
keywords with and
without corresponding end
statements, fix the function style
to be consistent. If there are extra end
statements in the
file by mistake, remove them. If you want more than 16 levels of nesting,
consider using the MATLAB class system. Often the function nesting level drops
and the code becomes simpler to understand when you use classes instead of
nested functions.