永发信息网

matlab GUI控件设计中,在调用pushbutton按钮callback,提示错误,求解答

答案:1  悬赏:80  手机版
解决时间 2021-03-02 03:09
  • 提问者网友:留有余香
  • 2021-03-01 06:31
h_main=figure('name','a demo of','menubar','none','numbertitle','off','position',[100,100,300,100]);
h_edit=uicontrol('style','edit','backgroundcolor',[1,1,1],'position',[20,20,50,20],...
'tag','myedit','string','1','horizontal','left');
h_but1=uicontrol('style','pushbutton','position',[20,50,50,20],'string','INC',...
'callback',['h=findobj(gcf,"tag","myedit");','v=eval(get(h,"string"));','set(h,"string",int2str(v+1));']);
??? Error using ==> h=findobj(gcf,"tag","myedit");v=eval(get(h,"string"));set(h,"string",int2str(v+1));
Error: The input character is not valid in MATLAB statements or expressions.

??? Error while evaluating uicontrol Callback
最佳答案
  • 五星知识达人网友:鸠书
  • 2021-03-01 06:52
回调函数中的字符串应该用两个单引号('')括起来,而不是用双引号(")。
一共有8处需要替换,即:
h_but1=uicontrol('style','pushbutton','position',[20,50,50,20],'string','INC',...
'callback',['h=findobj(gcf,''tag'',''myedit'');','v=eval(get(h,''string''));','set(h,''string'',int2str(v+1));']);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯