Code covered by the BSD License  

Highlights from
41 Complete GUI Examples

  • GUI_1() Demonstrate how to delete an entry from a uicontrol string.
  • GUI_10() Demonstrate how to make an image visible or invisible by pushbutton.
  • GUI_11()
  • GUI_12() Demonstrate how to control the mouse pointer from a GUI.
  • GUI_13() Demonstrate how to display & change a slider's position with an edit box.
  • GUI_14() Demonstrate colored text in a listbox, & how extract user's choice.
  • GUI_15() Demonstrate an edit text which has copyable but unchangeable text.
  • GUI_16() Demonstrate display & change a slider's position & limits with edit boxes
  • GUI_17() Demonstrate how to have a running clock in a GUI, and timer use.
  • GUI_18() Demonstrate the use of the buttondownfcn for an axes.
  • GUI_19() Demonstrate how to keep track of the number of times an action is taken
  • GUI_2() Demonstrate how to add a new entry to a uicontrol string.
  • GUI_20() Demonstrate how to get the chosen string from a popup.
  • GUI_21() Demonstrate how to get selection from a popup to an edit box & vis versa.
  • GUI_22() Demonstrate how to get selection from a popup to an edit box & vis versa.
  • GUI_23() Demonstrate finding which figure was current before callback execution.
  • GUI_24() Demonstrate how to get data from one GUI to another (data passing).
  • GUI_25() Demonstrate how to make an image loader.
  • GUI_26() Demonstrate how to make the choices in several popups mutually exclusive.
  • GUI_27() Demonstrate how to display the current location of the mouse in an axes.
  • GUI_28() Demonstrate uicontextmenu for an axes click.
  • GUI_29() Demonstrate the use of a uicontrol to manipulate an axes from a GUI,
  • GUI_3() Demonstrate how to hide a uicontrol from the user.
  • GUI_30() Same as GUI_29, except uses callback strings.
  • GUI_31() Demonstrate multiple uicontrol manipulations based on user choices.
  • GUI_32(str) Demonstrate how to get data from a GUI into the base workspace without
  • GUI_33() Demonstrate how to export data with context menu.
  • GUI_34() Demonstrate how to make a simple printscreen GUI. Note that this does
  • GUI_35() Demonstrate how to use toggle buttons to mimic tabbed panels.
  • GUI_36() Demonstrate how to make a custom dialog box which returns information.
  • GUI_37(str,time_out) Demonstrate how to make a password editbox, and nested function
  • GUI_38() Demonstrate bringing the focus to the figure after callback using JAVA.
  • GUI_39() Demonstrate use of nested functions for callbacks and other functions.
  • GUI_4() Demonstrate how to make a multiline editbox.
  • GUI_40() Demonstrate how to use an image as a background of a GUI.
  • GUI_41() Demonstrate how to save and load the state of a GUI system.
  • GUI_5() Demonstrate how to use a pushbutton to delete bits of string and how to
  • GUI_6() Demonstrate how to update one uicontrol with data from others.
  • GUI_7() Demonstrate how to store choice counters for multiple user choices.
  • GUI_8() Demonstrate how to tell which button in a uibuttongroup is selected.
  • GUI_9() Demonstrate one way to let the user know a process is running.
  • previewGUIs() This is a helper GUI which lets the user quickly view all of the example
  • contents.mSyntax Considerations for reading the M-Code:
  • View all files

41 Complete GUI Examples


Matt Fig (view profile)


27 Jul 2009 (Updated )

41 working GUIs to read and learn.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

function [] = GUI_25()
% Demonstrate how to make an image loader.
% Creates a GUI which looks for files with the extention .jpg in the
% current directory.  A listbox is populated with the names of all such
% files, and is empty if none exist in the current directory.  When the 
% pushbutton is activated, the current selection in the listbox is read 
% into a variable in the base workspace.  The name of the variable will 
% have a timestamp so as to minimize the chances of overwriting another 
% variable.  For example, say the selected image file is called Mypic.jpg  
% The base workspace variable will be Mypic_10_05_21 if the pushbutton was 
% pushed as 10:05:21 according to the system clock.
% Suggested exercise:  Modify the code so that the user could pass in
% the extention of the image file-type which they wished to load.  In the
% callback section, there should be some kind of check for indexed
% images, and appropriate action taken.  Further:  modify this file so that
% the user can pass in a directory name within which to search, or add a
% browse button to the GUI.
% Author:  Matt Fig
% Date:  7/15/2009

D = dir('*.jpg');  % or jpeg or whatever.
S.NAM = {D(:).name};  % Store the name of all items returned in D.
S.fh = figure('units','pixels',...
              'position',[450 450 400 200],...
              'name','Verify Password.',...
              'name','GUI_25'); = uicontrol('style','list',...
                 'position',[10 60 380 120],...
S.pb = uicontrol('style','push',...
                 'position',[10 10 380 40],...
                 'string','Load Image',...


function [] = pb_call(varargin)
% Callback for pushbutton.
S = varargin{3};
L = get(,{'string';'value'});  % Get the editbox string
    L = L{1}{L{2}};  % Give it a name for the base workspace.
    X = imread(L); % Read the image.
    % Next we will append a timestamp to the variable name so that we 
    % minimize the chances of overwriting a variable in the base 
    % workspace.  There are many other ways to handle this, so feel free to
    % experiment with alternatives.  
    str = [L(1:end-4),'_',strrep(datestr(now,'HH:MM:SS'),':','_')];
    assignin('base',str,X)  % Create the variable in the base workspace.
    % Also more could be done here as far as returning what kind of error,
    % or offereing other suggestions to the user, etc.
    fprintf('\t\t%s\n','No file selected, or read error.')

Contact us