How to pass handle of checkbox to another callback

2 次查看(过去 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

回答(2 个)

Walter Roberson
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')

Michael
Michael 2012-12-3
编辑:Michael 2012-12-3
Hi Walter,
Thanks for your fast reply.
I changed all callbacks to the line you wrote.
I received the following message:
??? Error using ==> Creat_menu>@(im)'SearchForBall(im,handel,''Basketball'')'
Too many input arguments.
??? Error while evaluating uipushtool ClickedCallback
I defined the SearchForBall function as follows:
function [ ] = SearchForBall( Image,check_box,Sport)
Michael
  1 个评论
Walter Roberson
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 CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by