File Exchange

image thumbnail

41 Complete GUI Examples

version (108 KB) by Matt Fig
41 working GUIs to read and learn.


Updated 27 Jan 2010

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week Popular File 2010 2012 2013

This is a collection of GUIs meant to serve either to answer specific questions about writing GUIs or as a teaching tool to aid in learning how to write MATLAB GUIs without GUIDE. Many of these are inspired directly from the newsgroup.

The questions/files are written in approximate order of complexity, so intermediate users may want to skip the first several files.
The questions answered include:

1.How do I manipulate the strings in a uicontrol? GUI_1, 2, 4, 5, 13, 14, 15, 20, 21, 22, 37
2.How do make a uicontrol invisible/visible? GUI_3, 35 (See also GUI_10 for images)
3.How do I make a multi-line edit box? GUI_4
4.How can I initialize an editbox so that the cursor is blinking at startup?  GUI_4, 24, 37
5.How can I let the user of my GUI know his actions are futile (or producing no results)? GUI_5
6.How can I tell which uicontrol is selected e.g., radiobuttons? GUI_6, 8
7.How do I tell how many times a uicontrol has been activated? GUI_7, 19, 28, 32, 33
8.How do I tell which button in a buttongroup is selected? GUI_8
9.How do I let the user know a process is running in the background? GUI_9
10.How can I set an image visible/invisible? GUI_10
11.How can I use a GUI to exit a FOR loop? GUI_11
12.How can I control the mouse pointer with a GUI? GUI_12
13.How do I access the value (current position) of a slider? GUI_13, 16
14.How do I use different colored strings in a listbox? GUI_14
15.What is the difference between 'listboxtop' and 'value' in a listbox? GUI_14
16.How do I make text that can be copied but not changed? GUI_15
17.How can I allow the user of my GUI to set the range of a slider? GUI_16
18.How can I display a digital clock in my GUI? GUI_17
19.How can I use a timer in a GUI? GUI_17
20.How do I use the buttondownfcn on an axes object? GUI_18, 28
21.How do I make a callback talk to another callback? GUI_19
22.How can I get the string from a popup or listbox? GUI_14, 20, 21, 22, 31, 32, 33
23.How can I set the string in a popup or listbox? GUI_21, 22
24.How can I add to the string in a popup or listbox? GUI_22
25.How do I tell which figure/axes was current before my callback executed? GUI_23
26.How do I get data from another GUI? GUI_24
27.How do I make a GUI to open image files only? GUI_25
28.How can I make popup choices mutually exclusive? GUI_26
29.How can I show the current pointer location in axes coordinates? GUI_27
30.How can I use uicontextmenus? GUI_28, 33, 39
31.How do I make my GUI control an axes in another figure? GUI_29, 30
32.What are callback strings? GUI_30
33.How can I make it so that when one of the figures closes, they all close? GUI_24, 29, 30, 41
34.How do I make several uicontrols interact in a more complicated GUI? GUI_31, 32, 33, 41
35.How do I get data from a GUI to the base workspace? GUI_25, 32, 33, 36
36.How can I use a GUI to take a screenshot of my desktop? GUI_34
37.How do I make toggle buttons act like tabbed-panels? GUI_35
38.How do I make a custom dialog box which returns a string to the base workspace? GUI_36
39.How can I make a password editbox that has the ***** symbols? GUI_37
40.How can I use nested function as callbacks? GUI_11, 17, 34, 36, 37, 39, 40, 41.
41.How can I use uiwait in a GUI? GUI_11, 34, 36, 37
42.How do I use JAVA in my GUI? GUI_38
43.How do I force the figure to maintain focus between uicontrol activations? GUI_38
44.How do I save an axes as an image? GUI_39
45.How can I make a simple drawing program? GUI_39
46.How can I set a button's background to match an image? GUI_40
47.How can I save the state of a system of GUIs to use later? GUI_41

I am open to hearing any suggestion as to other questions which could be covered in the collection. Such suggestions need not be basic. Please read the pdf file prior to use. Also the contents.m file contains brief descriptions of each GUI.

Please email me if an error is found, either in the documentation or coding. Thanks.

Cite As

Matt Fig (2021). 41 Complete GUI Examples (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (207)

Hong Sheng Lee

Ivo Drisga

Thank you very much. Helps me a lot!

Fabiano Miranda

Masoud Aslannezhad

Thank you very much for great sources.
Would you please give us your email?!

Karson Sommer

mohan khedkar

Hello sir, I am taking real time data in matlab and want to display in GUI.When i use fixed data to display in GUI it shows correct graph.But in case of real data,its not working.When i run program in GUI ,it shows graph in MATALB instead of GUI,where is the problem sir?
In GUI,i am calling MATLAB file by using the command: run('file name of .m').

Rene M

Hugo Mendes

Benjamin John Solomon

Ramon Ticzon

Abdelfatah Teamah

Thomas Schenk

Great examples.
Just one question:
Why we will we find S alwas as third argument?: (S = varargin{3}; and h = varargin{1}) ?;
Is this (hard)coded in MATLAB, ( Guide / uicontrol) ?

Michael Levashov

Varsha Harpale



Jens Koopmann

joseph akpan

Khine zar

Thank you for your kind !...
It is very helpful to me !..

Kate Derosier

Ghassen Trigui

Will Polsky

How do I upload data to a table in my GUI

Christian Silvano

Ahmed Hemdan

Awesome !!

Akade parfait

Manoj Kumar

great work!! Thanks for the examples where really useful.
But one question regarding the handles i can get over an histogram plot. Can you help me on that?

Reza Nurohim


Respects... 5+1 stars

ekasit kanjanakaew

thx for shared

Atul Kumar

Adismael Pinheiro

Justin Harrell

Ruoyun Emily Ma


perfect! :)

shruba gangopadhyay

absolute gold mine :)

Marco Rosatello


Adi Setiawan

Tamir Friedrich


Getnet Demil

Muhdnoor Muhdhamdi

Bruno Depizzol

Piotr Derug

Mariusz Andrzejczak

Great. I'm impressed. Thank you

Hamidreza Mirtaheri

Rob Campbell


Guillermo Quintas





megan miller



Thank you, found this too late unfortunately but I can still use it for present/future projects!

Theepa hari

How can i use GUI clock in my gui application please explain me in detail



Amielyn Kabiling


thank you :)

petch tansangworn

Kai Zhang

Great work! Thanks for the efforts of creating a group of examples to demonstrate how to create GUI without GUIDE.



li haitao

Eman Johnson

Very useful. Thank you!

kai zhao

very helpful

vincent plona

thanks a lot, very usefull

Khemais Moussa


An Do

My matlab Guide cannot render. Could anyone help me to fix this!

Tyler TONG

An Do

Vishal gautam

Hello everyone ,is there any one could help me to create GUI like nnd7sh which is tool for neural networks


Canh Thanh Phan

Thank you!

S. Gopal

Very nice...
These are very helpful.

Duong Nguyen Van

Great, very useful, thanks Matt.

yengpeng cheow

Hi, I would like to build a GUI which develop the antenna structure based on the antenna parameters (antenna length, width, etc). Can you help me in building the antenna structure of dipole antenna with the input parameter antenna length and width? Thanks. :D

hong ngoc nguyen


Madhubabu Malakonda

. Build a GUI using MATLAB to display a 16 symbol/digit DTMF panel.
Add a noise button in the GUI to add some fixed amount of noise to the signal such that SNR is 20 dB

plz provide the source code given mailid

Vikesh Desai

Build a GUI using MATLAB to display a 16 symbol/digit DTMF panel. Here is how it should work. Upon punching any digit on the DTMF panel, the corresponding symbol/digit will be displayed in time and played out. Add a noise button in the GUI to add some fixed amount of noise to the signal such that SNR is 20 dB. Upon pressing the noise button, the noisy waveform will be shown in time and frequency. Finally add a decode button. Upon pressing the decode button, the decoder will detect the symbol/digit. Make sure your design is robust.
Please Help me for above Question...?
Thank you

Kristina Berlage

I am writing a MATLAB code and have a user defined function behind the code. The GUI has 5 different Materials (checkboxes) that represent 5 materials in the UDF. I want the GUI to compute a value based on which material is selected and how many are selected. The UDF does that, but I don't know how to set the checkboxes to equal certain vaalues (ie Material 1 checkbox = 1, Material 2 checkbox = 2). any ideas?

Fadi Must

Fadi Must

Thank you very much

Tahani Alamri

Thank you so mutch

John Carlo Aquino

Hi Sir Matt Fig can you help me?

I want to make 1 GUI which has 1 start button and 1 done button. by pressing 'start' , it records sound from my cellphone that was connected to my laptop and after pressing 'done' , it stops recording..
and another GUI has 'Play' and 'stop' buttons, by pressing play button the recorded music will play and shows FFT graphs and by pressing stop it will stop playing.

amirreza sojoodi


mohamed meridjet

Irene Lia Arabes

How do i add music/song in my GUI?


hi. thanks for the useful info so far. however, i still have a question; how can i make an interactive listbox programmatically so that i can use it in a GUIDE built GUI?


Thank you very much. It is a very complete work!

Tan Nguyen

This is an amazing work

Mani Ahmadian

Thank you very much. You are so generous.



CEC Landran

piyush dugar

Gil Bachar

Great submission, helps a lot making my own GUI

Jason Oh

super thanks, Matt


I was wondering if you covered some topics that I'm looking for in your precious exampls.

1- How to make tabs for GUI, like new IE, firefox and ... they all have tabs on the top.

2- How to open a new GUI from within a GUI and pass the variables of the first GUI to second. Sometimes I can't squeez all the buttons and menues to keep te in the same form, I am thinking of makig ore commercial! lol

Specificly I want to know how to do these things when I'm using the GUIDE not writing the whole GUI with codes!

Many regards and thanks for sharing your experience and knwoledge for free ;)


matlab central confirms the choice upon other sw.

Mr Smart

Mateo Sundquist

Very practical, well-thought out examples. Thanks!

vladimir avalos

excellent examples!!!



Super job and well thought out.

Very practical with numerous possible applications!!

Zoltán Csáti

I found a bug in GUI_21. If I write 't' into the editbox (since two and three contains 't'), it cannot select which number should be displayed on the popup-menu. It is not a real bug, since it only produces a warning and can be fixed throuhg the GUI.
Anyway, this collection of GUIs is very useful.

Jonathan Lister

Fig = figure('Name','Matt'); % LOL!!!

Iman Ansari

Antonio Fuentes

Amazingly useful. Such a great work.


How to place an image in the axes without brosing the image. By giving some path or filename ?


Awesome start for a beginner

Rebecca Carter


thanks for sharing these!! very helpful

Emad Ravari


This very helpful beginers


Awesome! Much appreciation Matt!


Dee Chen

Really helpful, awesome!


thanks Matt

Shamir Alavi

Lee Smith

Thanks Matt, this is very useful.

I have a syntax question about callbacks.
Most of your GUIs use:
'callback',{@pb_call,S}); %% GUI_1
although the same result comes from
Can you steer me to documention that would help me understand more about the options? Starting with the necessity or use of a cell with attribute?

Thanks in advance


Great, very useful, thanks Matt.


I can not download these file
can someone send it to me by email ?


Excellent, great job. You are very generous. Thank you very much.

Abhishek Ghosh

your humble effort made my project, what more can i say, a bible for matlab gui's.


how can I divide in many m-file my GUI? I want build a main m-file that call other m-file one for one figure. this to limit the length of m flie.
this using structure date learn by Mat GUI exemples.

Thanks much!

aina mansor

can anyone help me to get a matlab simulink for DIGITAL HEARING AID


hey Matt Fig,
can u help me?

i want to make 1 gui which has 1 start button and 1 stop button. by pressing 'start' , it generates or play sound and after pressing 'stop' , it stops sound..
and another GUI has 'start' and 'stop' buttons, by pressing start button 1 'while loop' is run and after pressing stop 'while loop' is ended.


excellent job
thanks from Italy


Thank you very much, this post very usefull

Andreas Bonelli


Hi, i have two gui windows. i want to a push button in first GUI , such that when i click this push button, i want to make a panel visible in second GUI, which was initially set to invisible.

Can any one help me to do this?


Awesome. Thanks Matt!


I work with the GUIDE tool
I need to display a inputdlg before I close my GUI...

1.Where I need to define
the closeRequestFcn

2. Where to write the callback?
function my_closereq(src,evnt)




Mr Smart


Nik F


josh andrew

Mr Smart

Nice Examples


Matt Fig

To fremond,

What do you mean, "open" the file? For editing? Just type:

>> edit GUI_1

If you have other problems, please email me instead of using the ratings area.

fremond khoo

can u teach me how to open the file?..i am currently using matlab 7.0 and while i was opening the file..this error comes along while i try to open GUI 1

??? Error: File: D:\toolbox\matlab\uitools\uiopen.m Line: 179 Column: 1
Illegal use of reserved keyword "catch".

is it compatibility problem?..can someone enlighten me?..please teach me how to open an m-file correctly too if you are so kind..because im having the same prob while opening the other m-file..thanks so much



Sean de

This bundle is really helpful to have kicking around for the occasional GUI-related question. Thanks Matt!

Sean de

John D'Errico

Beautyegg Skylake

Sisi Ma


it will be very useful to me
thanks so much

Camille Couzi

One question about GUI_27: How can I get the same results, knowing that my figure of GUI, and all buttons and panels are deinfed in units normalized?
Thanks you very much!!!

Luis Lacerda

hello, i have read the examples but i still can´t answer my can you make a GUI subplot something in another GUI? Not just plot, because what i am plotting has parameters altered by the called GUI..


Erdal Bizkevelci


excellent examples.

GUIs are excellent case for object oriented code. It would be great to see an example of thet.


Thanks for this - very well written. Just need to find the time to practice but thanks for sharing this with us!

Cesar Chillon

Many thanks, great work


GUI_37 in the above file works perfectly in MATLAB 2007a. It opens a GUI where a password needs to be entered. The characters are displayed as *****. In MATLAB 2008b, a character is turned into an asterisk very slow (first, the actual character is showed) and then the cursor is set to the left of the edit text instead of to the right of the asterisk.

Can anyone tell me if this is a bug in MATLAB 2008b, or if it is an error in the code from the File Exchange?


Great files by the way, they have been very useful!

Examples Learn By

Thank you for sharing, it is really useful


I will be thankful for you until my life time,really you saved me with your great works...

Niks Nike

Excellent work, really very helpful to us..

Thank you Matt Fig.

Husam Aldahiyat

Matt Fig

Lorenzo and Jie,
There are many ways to do the same thing in MATLAB! The approach I would have taken in solving the S.E. for GUI_2 involves adding only one line of code, and no call to PAUSE. Feel free to email me if you have more questions.

Lorenzo Guerrasio

sure an excellent job.
Like jie zhang, I also spent sometime realizing that a pause was necessery in your suggested exercise for GUI 2. Is it planned a "spoiler" for excercise?

Muhammad Bashir


I have made Gui for excel data ploting in Matlab. I did it using the video of Mr Doug ( The gui works fine but the command wndow gives following error.

mainGui>pushbuttonLoadXLS_Callback at 130
setPopupString(handles.popupmenuX,eventdata, handles)
Error in ==> gui_mainfcn at 96
Error in ==> mainGui at 42
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback>

The gui i m using is:

setPopupString(handles.popupmenuX,eventdata, handles)
setPopupString(handles.popupmenuY,eventdata, handles)
function setPopupmenuString(hObject, eventdata, handles)

[numbers, colNames]=xlsread(fileName);

function [x y] = readExcelColumns(fileName, xColNum, yColNum)

a = xlsread(fileName);

x=a(:, xColNum); % x-axis values containing all the rows and column #
y=a(:, yColNum); % y-axis values containing all the rows and coumn #

function updateAxes(hObject, eventdata, handles)

xColNum = get(handles.popmenuX, 'value');
yColNum = get(handles.popmenuY, 'value');
fileName= handles.fileName;

[x y] = readExcelColumns(fileName, xColNum, yColNum)


Andrew Newell

Something went wrong with my previous submissions, so I am going to start from the beginning. This is a terrific resource, and the preview GUI makes it very easy to browse. However, there were a few minor problems (on a Mac, at least):

A few GUIs (6, 8, 26) had truncated button labels.

In GUI 26, "alfa" should be "alpha".

The documentation for GUI 12 says that nothing happens when it is run on a Mac. Actually, I get the following error messages:

??? Undefined function or method 'pb_call' for input arguments of type 'struct'.

??? Error while evaluating uicontrol Callback

(This was easily fixed by inserting a function pb_call that closes the window.)

Finally, in GUI 40, Restore doesn't always restore all the button colors if more than one button has been pressed.

I initially gave this package a 4 rating because of these minor problems, but it really deserves a 5.

Andrew Newell

Two corrections from the previous post: I realized that all the buttons in Gui 40 did have an effect - I wasn't looking closely enough or clicking repeatedly. However, Restore doesn't always restore all the button colors.

Also, I changed my mind and gave it a 5 rating.

Andrew Newell


When working on your suggested exercise, it took me quite a while to realize should put "pause(0.01)" in the KeyPressFcn_callback, which gives time for updating, to avoid possible inconsistency between the string actually in the edit box and addstr. Maybe mention this in the tutorial.
Good job!



Aurelien Queffurust

I ran alll the GUIS under Windows with MATLAB R2009b
Wow , this submission is a great idea.
M-files are well documented , your GUIs are both easy to understand and to use.
Suggested exercise is also a good idea.

My favorites: GUI_12 , I love fun !
GUI_27 which is a nice feature to display current location of the mouse
GUI_35 with the fake tabs
GUI_39 how to make "Paint" inside MATLAB!

Just one remark about GUI_22
if you enter in the edit box 'one129' then 'on' the popup disappears.

Good work!

Nathan Greco


very useful. A lot of things that are vaguely refered to in the documentations got much clearer to me after going through your examples. Thanks!


Great Job Matt
I have a small question....
Do you know whether it is possible to play a Wav.file in GUI and at the same time be able to stop it when ever you want?

I've tried using "audioplayer" but I faced two problems:
1- The Wav. file ran for only a second, and I used a pause to solve the problem [not a smart solution anyway]

2- I could stop the Wav.file using "stop(player)".. as I have a problem in connecting the two push_buttons [start and stop]

Do you have any tips, suggestions?
Thanks in advnace and Happy new year


Excellent example files.

Used them to learn how to structure my Matlab code and build a GUI.

Thanks a million.


Thank you very much!


thanks,this really helps me a lot!I'll keep learning it!

Damien Altzheim

Awesome!! Just what I was looking for.

Rachel Laughs

Okay wow. I know I already posted feedback, but this set of examples is so amazing as a tutorial that I had to come back and say that every beginner should study this entire package. This has to be the best file I've found all year, hands down. Thank you for providing this!!

Rachel Laughs

What an amazing collection. Thank you so much for this!

Is there an available "answer guide" for the suggested exercises you have listed in the files? I am sadly already stuck on the second one and don't want to move on until I understand it

Ahsan Chaudhry

Awesome.... You made my day!!! I was struggling with gui... thanks a lot...


In GUI_32, if i press the delete button(key), it does not delete the next character instead it will consider it as a character and adds to the existing string

Krishna Lalith

Excellent. Great Job.




vivian Fang

These are really helpful. Thank you very much!

Matt Fig

GUI_34 has a custom menubar. None of the GUIs in this collection are programmed with GUIDE. Please email me if you have more questions.

Matt Fig

Hello CyberFrog,
I am not sure what you mean by a "menu title" in GUI_25. There isn't supposed to be a menubar, if that is what you mean. I am using 2007b, and everything looks like it should here.

No *.fig file is generated because these are M-file GUIs. GUIDE works by generating two files, an M-File which has the code, and a figure file which has the graphics. These are simply two different ways of doing GUIs in MATLAB. I much prefer to write my GUIs without GUIDE for many reasons, only one of which is that I need to keep track of only one file!

This collection, as is stated in the description, is meant to help people write GUIs without using GUIDE.

Matt Fig

You are correct. I didn't mention resizable GUIs because I make all of my own GUIs non-resizable. Is there something you have in mind in particular? If so email me with your suggestion, and I may include it in the next update. Thanks.


Absolutely Superb !!

Thanks for such a didactic, well commented set of example. The exercises are a great idea too.

One thing you never touched though, is the resizing of the GUIs. Was that intentional ?



thank you for understanding, and this is a great set and deserve a 5star for its completeness.

Luigi Giaccari

Arnaud Thabot

Vishakha Bhagat

manoj singh

awesome work really very helpful

Darren Rowland

A stellar FEX contribution. Must read material
for any GUI developer.

Matt Fig

Thanks someone,
BUG! I should be using listboxtop, not value. Thanks, I will update that too.
Also, the suggestions for added exercises are coming into my email. Keep them coming! Any other GUI suggestions are welcome, simple or complex.


A VERY useful submision for all ages of programmers.

In GUI_12, I have to actually click on the the "color" to get the "print choice" button to work properly. Otherwise the last color "selected" is printed (not current displayed color).
Bug or feature?

A (very minor) typo in GUI_24 on line 23:
% No make a simple plot.
should be:
% Now make a simple plot.

This submission could easlily become the MATLAB GUI FAQ!
Great job Matt!!!

Matt Fig

I like the contents.m idea, and I might as well since a typo has already been found.

In the pdf I refer to a comment in GUI_30. I should have put GUI_32. File will be updated.


this first class ML senior has offered an enormous amount of time to create this exhaustive suite of working and highly educational GUI examples to our community...
both novices, in particular, as well as more advanced users will find a lot of good stuff in those exemplary functions...
this submission certainly will find its way into many CSSM threads as a hint for solutions as well as good programming practice...

altogether, hats off not only to a ML cognoscente but also to a teacher who clearly seems to be fond of people 'doing' ML...


ps: matt, what about a small CONTENTS.M, which would be easier than the (nice) PDF you proved (just a pedestrian thought)...

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!