得到菜单句柄,假设现在是handles.sheye10,那么在回调中写
ThisMenuHandle = handles.sheye10;
MenuChecked = get( ThisMenuHandle, 'Checked');
if strcmp( MenuChecked, 'on' )
set( ThisMenuHandle, 'Checked', 'off' ) ;
else
set( ThisMenuHandle, 'Checked', 'on' ) ;
end
得到菜单句柄,假设现在是handles.sheye10,那么在回调中写
ThisMenuHandle = handles.sheye10;
MenuChecked = get( ThisMenuHandle, 'Checked');
if strcmp( MenuChecked, 'on' )
set( ThisMenuHandle, 'Checked', 'off' ) ;
else
set( ThisMenuHandle, 'Checked', 'on' ) ;
end
谢谢
ThisMenuHandle = handles.sheye10;
这句话还是不太会用,在我这里老出错
错误提示如下:
Error in ==> E:\MyMatlabApp\hf_choose.m
On line 3 ==> ThisMenuHandle = hf_menu.hf_sub1;
??? Error while evaluating uimenu Callback.
我不知道怎么在function中获取gui对象的窗口句柄
问题在哪里呢?
-----------------------------------------------------------------
我的figure窗口的菜单代码如下:
hf_menu=uimenu('label','数据文件(Data)','Position',8);
hf_sub1=uimenu(hf_menu,'label','中心轴深度剂量曲线','callback','hf_choose(1)');
hf_sub2=uimenu(hf_menu,'label','5mm深度X离轴曲线','callback','hf_choose(2)');
hf_sub3=uimenu(hf_menu,'label','5mm深度Y离轴曲线','callback','hf_choose(3)');
------------------------------------------------------------
回调函数hf_choose(x)如下:
function hf_choose(x)
if x==1
ThisMenuHandle = hf_menu.hf_sub1;
elseif x==2
ThisMenuHandle = hf_menu.hf_sub2;
else
ThisMenuHandle = hf_menu.hf_sub3;
end
MenuChecked = get( ThisMenuHandle, 'Checked');
if strcmp( MenuChecked, 'on' )
set( ThisMenuHandle, 'Checked', 'off' ) ;
else
set( ThisMenuHandle, 'Checked', 'on' ) ;
end
----------------------------------------------------