Using uimenu and the callback to a function

조회 수: 9 (최근 30일)
Robert Jones
Robert Jones 2012년 3월 1일
Hello, I am having trouble getting 'callback' to work the way I expected it. For a menu labeled "Setup" how can I get back to three unique functions to serve on of three purposes? Here is what I have been attempting to do:
mh(5) = uimenu('Label','Setup');
uimenu(mh(5),'Label','Config1','Callback','{@loadConfig1}');
uimenu(mh(5),'Label','Config2','Callback','{@loadConfig2}');
uimenu(mh(5),'Label','Config3','Callback','{@loadConfig3}');
function loadConfig1()
(function 1 programming)...
function loadConfig2()
(function 2 programming)...
function loadConfig3()
(function 3 programming)...
I placed stops in the code to see if I was coming back to the loadConfig functions and I do not seem to be. I am relatively new to MatLab programming...
Bob
p.s. is there a way to remove whitespace from posted questions? I had to use the enter key to get my questions preview to look right.
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 3월 1일
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

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

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 3월 1일
Don't use ' ' around the callback:
...'callback',@loadConfig3)
More works for me:
function ans_uimenu
mh(5) = uimenu('Label','Setup');
uimenu(mh(5),'Label','Config1','Callback',@loadConfig1);
uimenu(mh(5),'Label','Config2','Callback',@loadConfig2);
uimenu(mh(5),'Label','Config3','Callback',@loadConfig3);
function loadConfig1(src,evt)
pi%(function 1 programming)...
function loadConfig2(src,evt)
exp(0)%(function 2 programming)...
function loadConfig3(src,evt)
2
  댓글 수: 4
Robert Jones
Robert Jones 2012년 3월 1일
Sorry to be a bother. I dont understand (src,evt)...
Sean de Wolski
Sean de Wolski 2012년 3월 1일
Callback functions are automatically passed two input arguments: the source calling them, and eventdata. These have to be accepted (or declined with a ~) but must be present of the callback will fail with a "too many inputs" error.
web([docroot '/techdoc/matlab_prog/f9-39541.html#f9-42494'])

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by