Combine Event Handlers as MATLAB Local Functions

This example shows how to consolidate event handlers into a single file using local functions.

Create the mycallbacks.m file containing three event handler routines, myclick, my2click, and mymoused, implemented as local functions.

function a = mycallbacks(str) 
a = str2func(str);

function myclick(varargin)
disp('Single click function')

function my2click(varargin)
disp('Double click function')

function mymoused(varargin)
disp('You have reached the mouse down function')
disp('The X position is: ')
disp('The Y position is: ')

The call to str2func converts the input character vector to a function handle.

Create the control.

h = actxcontrol('mwsamp.mwsampctrl.2',[0 0 200 200],gcf,'sampev')

Register Click event.


Related Topics