フィルターのクリア

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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by