MATLAB Creating Graphical User Interfaces

(Barry) #1

14 Examples of UIs Created Programmatically


mPlotTypes is a 5-by-2 cell array that specifies graphing functions and data. The first
column contains the strings that are used to populate the pop-up menu. The second
column contains functions (anonymous functions) for creating the plots.
mPlotTypes = {... % Example plot types shownI
'plot(rand(5))', @(a)plot(a,rand(5));
'plot(sin(1:0.01:25))', @(a)plot(a,sin(1:0.01:25));
'bar(1:.5:10)', @(a)bar(a,1:.5:10);
'plot(membrane)', @(a)plot(a,membrane);
'surf(peaks)', @(a)surf(a,peaks)};

Because these variables are created in the main function, they are accessible from within
the nested callback functions in the same file.

Create the UI and Its Components


Like the mOutputArgs and mPlotTypes variables, the UI components are created inside
the main function, so they are accessible from within the nested callback functions in the
same file.

The Main Figure

This command creates the figure window:
hMainFigure = figure(... % The main figure
'MenuBar','none', ...
'Toolbar','none', ...
'HandleVisibility','callback', ...
'Color', get(groot,...
'defaultuicontrolbackgroundcolor'));


  • Setting the MenuBar and Toolbar properties to 'none' prevents the default menus
    from displaying and hides the default toolbar.

  • Setting the HandleVisibility property to 'callback' ensures that the figure
    object can be accessed only from within a callback.

  • The Color property defines the background color of the figure. In this case, it is set
    to be the same as the default background color of uicontrol objects, such as the
    Update push button. The factory default background color of uicontrol objects is
    the system default and can vary from system to system. This statement ensures that
    the figure's background color matches the background color of the components.


The Axes

This command creates the axes:
Free download pdf