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_26()
% Demonstrate how to make the choices in several popups mutually exclusive.
% Here we want three popups, with which the user can make three different
% choices from the same set of choices.  We want the users choices to be
% made in any order.  Once a certain value has been chosen through a popup,
% that value should disappear from the lists for the other popups.  The
% user is allowed to change past choices, and popup lists will reflect
% this.
% Author:  Matt Fig
% Date:  7/15/2009

S.fh = figure('unit','pix',...
              'position',[400 400 300 120],...
S.STR = {'alfa ';'beta';'gamma';'delta';'omega'};  % String for popups.
S.pp(1) = uicontrol('style','pop',...
                    'position',[20 70 70 30],...
S.pp(2) = uicontrol('style','pop',...
                    'position',[110 70 70 30],...
S.pp(3) = uicontrol('style','pop',...
                    'position',[210 70 70 30],...
S.pb = uicontrol('style','push',...
                 'posit',[20 20 260 30],...
                 'string','Print Choices',...
S.CHC = [0 0 0]; % To keep track of when a choice has been made.            
set(S.pp(:),'call',{@pp_call,S});  % All popups have the same callback.

function [] = pb_call(varargin)
% Callback for pushbutton, prints out the users choices.
S = varargin{3};  % Get the structure.
CHC = get(S.pp(:),{'string','value'});
fprintf('\n\t%s','Your choices are: ');

for ii = 1:3
    fprintf(' %s,',deblank(CHC{ii,1}{CHC{ii,2}}))


function [] = pp_call(varargin)
% Callback for popups.
[h,S] = varargin{[1,3]}; % Handle to cbo and structure.
N = ~ismember(S.pp,h); % The other 2 popup menus.
tmp = 1:3;  % Instead of calling find twice, or setdiff, see next 2 lines.
idx = tmp(~N); % The index to the current popup menu.
idxo = tmp(N);  % The indices into the other pops
S.CHC(idx) = 1;  % Let the subsequent calls know this choice has been made.
CHC = get(h,{'string','value'});  % String and value of h.
CHC = CHC{1}{CHC{2}};
ho = S.pp(N);  % Handles to the other two popups.
I = [1,2];  % Used in loop below.

for ii = I
    s = get(ho(ii),{'string','value'}); % Get the iith other pop str,val.
    s = s{1}{s{2}};  % The current string for the iith pop.
    tmp = I(I~=ii);  % Used to see if the other pop has made its choice.
    Str = S.STR;  % Get the master string.
    Str(strmatch(CHC,Str)) = [];  % Set this choice to null in master string.
    nm = get(ho(tmp),{'string','value'}); % Get the other pop's info.
    if S.CHC(idxo(tmp)) % The other-other pop has made a choice.
        Str(strmatch(nm{1}{nm{2}},Str)) = [];  % Set this choice to null.
    if strcmp(s,CHC)  % The iith pop had same as new h, move it.
        for jj = 1:length(Str)
            if ~strcmp(Str{jj},CHC)&&~strcmp(Str{jj},nm{1}{nm{2}})
                nm = strmatch(Str{jj},Str);
        nm = strmatch(s,Str); % Get the value for the iith pop.
    set(ho(ii),'string',Str,'value',nm,'callb',{@pp_call,S}) % Assignments.

Contact us