필터 지우기
필터 지우기

How to pass handle of checkbox to another callback

조회 수: 1 (최근 30일)
Michael
Michael 2012년 12월 3일
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