MATLAB: Hovering over figure menus gives error

editenderrorfigurehggetbehaviorMATLABmenupropertiessavetools

When I select the tools menu in a figure or any of the objects under the edit menu or try and save my figure, the following text displays in the command window:
Error: File: hggetbehavior.m Line: 56 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the
function "hggetbehavior".)
Error in isplotchild>validDataBehavior (line 77)
hBehavior = hggetbehavior(obj,'DataDescriptor','-peek');
Error in isplotchild (line 35)
if isvalid(obj) && validDataBehavior(obj, bfmode) &&
Error in plotchild (line 41)
ok(k) = isplotchild(ch(k), dim, bfmode);
Error in toolsmenufcn>LUpdateToolsMenu (line 280)
if ~isempty(axesList) && ~isempty(plotchild(axesList, 2,
true))
Error in toolsmenufcn (line 110)
LUpdateToolsMenu(hfig);
Error while evaluating Menu Callback

Best Answer

This error is either because of shadowing of the hggetbehavior built-in function or because the built-in function was edited. Whether shadowed or edited, the function now contains an error.
To check for shadowing, run the command:
>> which hggetbehavior
This should only give one output:
...\toolbox\matlab\graphics\hggetbehavior.m
To check if the function was edited, run the command:
>> edit hggetbehavior
Check that there are no errors in this function and that nothing has been changed. Specifically, ensure that all functions, loops, if statements... have proper starts and "end" statements.
This error is indicating that a statement is not inside a function, which could mean an "end" statement is ending something unexpected.