필터 지우기
필터 지우기

Trouble with callback with uimenus

조회 수: 1 (최근 30일)
Hanif
Hanif 2013년 5월 28일
function startup
File = uimenu(fig,'Label','File');
Message = uimenu(File,'Label','Message','Callback',@display);
end
function display(hObj,event)
disp('Hello world')
end
When this runs through and I click on the menu I get an error saying the following:
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in CreatingMenus>display
Error while evaluating uimenu Callback
Am I missing something really obvious?

채택된 답변

Jan
Jan 2013년 5월 28일
편집: Jan 2013년 5월 28일
Yes, you are missing something more or less obvious: When a line does not end with an semicolon, the built-in function display() is called to show the results in the command window. When you shadow the original display() function with a user-defined one, this function is called. And when it contains a line without a trailing semi-colon, it calls itself recursively.
Shadowing built-in function is a problem frequently. Therefore I'd avoid names like "display" and "startup" might lead to unexpected effects also.
Btw. you can investigate such problems by using the debugger. Set a breakpoint in the code and step through the program line by line. Then you can find out, where the recursion appears.
  댓글 수: 1
Image Analyst
Image Analyst 2013년 5월 28일
Good to know. Sometimes you don't know you've overwritten a built-in function until you have a major fecal/turbine impact. I didn't know display() was a built in function, and only sometimes do I do "which -all myFunctionName" to see if it's a built-in function. I should have noticed startup when I read his post, but I didn't - good catch on your part. He really won the exacta when he picked two reserved function names!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by