Write the Callback
Write the callback function for the component as a private helper function. The function
must have app, src, and event as the first three arguments. Here is an example of a
callback written as a private helper function.
methods (Access = private)
function mybuttonpress(app,src,event)
disp('Have a nice day!');
end
end
To write a callback that accepts additional input arguments, specify the additional
arguments after the first three. For example, this callback has accepts two additional
inputs, x and y:
methods (Access = private)
function addxy(app,src,event,x,y)
disp(x + y);
end
end
To assign this callback to a component, specify the component's callback property as cell
array. The first element in the cell array must be the function handle. Subsequent
elements must be the additional input values. For example:
b.ButtonPushedFcn = {@app.addxy,10,20};
Example: Confirmation Dialog Box with a Close Function
This app shows how to display a confirmation dialog box that executes a callback when
the dialog box closes.
When the user clicks the window's close button (X), a dialog box displays to confirm that
the user wants to close the app. When the user dismisses the dialog box, the CloseFcn
callback executes.
Add UI Components to App Designer Programmatically