Filter löschen
Filter löschen

How to pass handle of checkbox to another callback

1 Ansicht (letzte 30 Tage)
Michael
Michael am 3 Dez. 2012
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

Antworten (2)

Walter Roberson
Walter Roberson am 3 Dez. 2012
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 am 3 Dez. 2012
Bearbeitet: Michael am 3 Dez. 2012
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 Kommentar
Walter Roberson
Walter Roberson am 3 Dez. 2012
Do not quote the anonymous function. Not your
@(im)'SearchForBall(im,handel,''Basketball'')'
but just
@(im)SearchForBall(im,handel,'Basketball')

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by