MATLAB Creating Graphical User Interfaces

(ff) #1
When you make your selection, App Designer creates a template function and places your
cursor in the body of that function. Then you can update the function name and its
arguments, and add your code to the function body. The app argument is required, but
you can add more arguments after the app argument. For example, this function creates
a surface plot of the peaks function. It accepts an additional argument n for specifying
the number of samples to display in the plot.

methods (Access = private)

function updateplot(app,n)
surf(app.UIAxes,peaks(n));
colormap(app.UIAxes,winter);
end

end

Call the function from within any callback. For example, this code calls the updateplot
function and specifies 50 as the value for n.

updateplot(app,50);

Managing Helper Functions


Managing helper functions in the Code Browser is similar to managing callbacks. You
can change the name of a helper function by double-clicking the name in the Functions
tab of the Code Browser and typing a new name. App Designer automatically updates all
references to the function when you change its name.

If your app has numerous helper functions, you can quickly search and navigate to a
specific function by typing part of the name in the search bar at the top of the Functions

17 App Programming

Free download pdf