How to pass handle of checkbox to another callback
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I would like to pass an array of handles to uipushtool 'ClickedCallback'.
when I tried doing that I received the following error message:
??? Undefined function or variable 'handel'.
??? Error while evaluating uipushtool ClickedCallback
This is the code I wrote:
function [ ] = Creat_menu( fig ,im)
%Creat_menu adds push buttons to the import picture.
%The push buttons that are added reprisents the sport type.
%h = figure('ToolBar','none');
% Create the toolbar
th = uitoolbar(fig);
% Add a push tool to the toolbar
tennis = imread('tennis logo 16x16.jpg');%Read the image.
basketball = imread('basketball logo 16x16.jpg');%Read the image.
volleyball = imread('volleyball logo 16x16.jpg');%Read the image.
handel(1) = uicontrol('style','checkbox','units','pixels',...
'position',[0,0,80,15],'string','Color_Filter');
handel(2) = uicontrol('style','checkbox','units','pixels',...
'position',[0,20,100,15],'string','Variance_Filter');
handel(3) = uicontrol('style','checkbox','units','pixels',...
'position',[0,40,100,15],'string','User Algoritem');
handel(4) = uicontrol('style','checkbox','units','pixels',...
'position',[0,60,100,15],'string','Matlab Algoritem');
tennis_pth = uipushtool(th,'CData',tennis,...
'TooltipString','tennis',...
'HandleVisibility','off',...
'ClickedCallback','SearchForBall(im,handel,''Tennis'')'...
);
basketball_pth = uipushtool(th,'CData',basketball,...
'TooltipString','basketball',...
'HandleVisibility','off',...
'ClickedCallback','SearchForBall(im,handel,''Basketball'')'...
);
volleyball_pth = uipushtool(th,'CData',volleyball,...
'TooltipString','volleyball',...
'HandleVisibility','off',...
'ClickedCallback','SearchForBall(im,handel,''Volleyball'')'...
);
end
Thanks,
Michael
0 个评论
回答(2 个)
Walter Roberson
2012-12-3
You are defining handel within Creat_menu. The handel that appears when you create those callbacks is in string form. Strings for callbacks are evaluated in the context of the base workspace... and in that workspace, handel does not exist.
Define your callbacks as anonymous functions instead, such as
'ClickedCallback', @(im) SearchForBall(im, handel, 'Tennis')
0 个评论
Michael
2012-12-3
编辑:Michael
2012-12-3
1 个评论
Walter Roberson
2012-12-3
Do not quote the anonymous function. Not your
@(im)'SearchForBall(im,handel,''Basketball'')'
but just
@(im)SearchForBall(im,handel,'Basketball')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!