4.94118

4.9 | 36 ratings Rate this file 1138 downloads (last 30 days) File Size: 107.63 KB File ID: #24861

41 Complete GUI Examples

by Matt Fig

 

27 Jul 2009 (Updated 27 Jan 2010)

Code covered by the BSD License  

41 working GUIs to read and learn.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.5 (R2007b)
Zip File Content  
Published M Files Syntax Considerations for reading the M-Code:
Other Files
contents.m,
GUI_1.m,
GUI_10.m,
GUI_11.m,
GUI_12.m,
GUI_13.m,
GUI_14.m,
GUI_15.m,
GUI_16.m,
GUI_17.m,
GUI_18.m,
GUI_19.m,
GUI_2.m,
GUI_20.m,
GUI_21.m,
GUI_22.m,
GUI_23.m,
GUI_24.m,
GUI_25.m,
GUI_26.m,
GUI_27.m,
GUI_28.m,
GUI_29.m,
GUI_3.m,
GUI_30.m,
GUI_31.m,
GUI_32.m,
GUI_33.m,
GUI_34.m,
GUI_35.m,
GUI_36.m,
GUI_37.m,
GUI_38.m,
GUI_39.m,
GUI_4.m,
GUI_40.m,
GUI_41.m,
GUI_5.m,
GUI_6.m,
GUI_7.m,
GUI_8.m,
GUI_9.m,
license.txt,
previewGUIs.m,
Usage_notes.pdf
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (53)
28 Jul 2009 us

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...

us

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

28 Jul 2009 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.

28 Jul 2009 someone

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!!!

28 Jul 2009 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.

29 Jul 2009 Darren Rowland

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

30 Jul 2009 manoj singh

awesome work really very helpful

05 Aug 2009 Vishakha Bhagat  
09 Aug 2009 Arnaud Thabot  
11 Aug 2009 Luigi Giaccari  
11 Aug 2009 creek

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

11 Aug 2009 Ahmed  
13 Aug 2009 Tanguy

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 ?

13 Aug 2009 Matt Fig

Tanguy,
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.

06 Sep 2009 CyberFrog

Hi matt, great collection of gui examples, really useful!

I have 2007b and I tried running example 25 but no menu title appears, is this a compatibility problem?

One more question too being an absolute beginner here, how come no .fig file is generated when running the .m file code? i.e. in guide this is automatically generated?

Cheers

Cyberfrog

06 Sep 2009 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.

07 Sep 2009 CyberFrog

Hi Matt,
Woops, I thought the uimenu function was for the menu bar only.
Is it fair to assume then that if a gui is programmed without guide and you wish to add a menu bar, the property menubar is the only way to do it? Sorry for the general question but I have just been lucky enough to take on this rather large code which I think was not written in guide to start with (but it still has a .fig file).

Do you happen to have an example with a customised menubar gui that is programmed without using guide?

Like yourself I am very much inclined to program GUI's rather than using GUIDE.

Many thanks

07 Sep 2009 Matt Fig

Cyberfrog,
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.

11 Sep 2009 vivian Fang

These are really helpful. Thank you very much!

29 Sep 2009 Herve  
22 Oct 2009 Alain  
23 Oct 2009 Ashwini Deshpande  
26 Oct 2009 Krishna Lalith

Excellent. Great Job.

26 Oct 2009 Ashwini Deshpande

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

03 Nov 2009 Ahsan Chaudhry

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

09 Nov 2009 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

13 Nov 2009 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!!

16 Nov 2009 Damien Altzheim

Awesome!! Just what I was looking for.

27 Nov 2009 ??

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

03 Dec 2009 Faith

Thank you very much!

16 Dec 2009 Brian

Excellent example files.

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

Thanks a million.

28 Dec 2009 Sermed

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
Sermed

08 Jan 2010 Daniel

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!

08 Jan 2010 Nathan Greco  
02 Feb 2010 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!

07 Feb 2010 Jie Zhang

Thanks!

07 Feb 2010 Jie Zhang

GUI_2
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!

15 Feb 2010 Andrew  
15 Feb 2010 Andrew

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.

15 Feb 2010 Andrew

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.

02 Mar 2010 Muhammad Bashir

Hej,

I have made Gui for excel data ploting in Matlab. I did it using the video of Mr Doug (http://blogs.mathworks.com/pick/2007/08/13/video-series-reading-excel-data-into-matlab-with-a-gui/). 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
feval(varargin{:});
Error in ==> mainGui at 42
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback>

The gui i m using is:

<handles.fileName=uigetfile('*.xls')
guidata(hObject,handles)
setPopupString(handles.popupmenuX,eventdata, handles)
setPopupString(handles.popupmenuY,eventdata, handles)
set(handles.popmenuX,'callback','mainGui(''updatedAxes'',gcbo,[],guidata(gcbo))')
set(handles.popmenuY,'callback','mainGui(''updatedAxes'',gcbo,[],guidata(gcbo))')
function setPopupmenuString(hObject, eventdata, handles)

fileName=handles.fileName;
[numbers, colNames]=xlsread(fileName);
set(hObject,'string',colNames);

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)

plot(handles.axes1,x,y)>

02 Mar 2010 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?
Thanks!

04 Mar 2010 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.

07 Mar 2010 Husam Aldahiyat  
29 Apr 2010 NIKHIL Mothukuri

Excellent work, really very helpful to us..

Thank you Matt Fig.

30 Apr 2010 marwen

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

23 May 2010 Examples Learn By

Thank you for sharing, it is really useful
http://learnbyexamples.org/category/matlab

05 Jun 2010 Mark

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

05 Jun 2010 Mark

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?

07 Jun 2010 Cesar Chillon

Many thanks, great work

14 Jun 2010 Christian

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

30 Jun 2010 Grunde

Hi,
excellent examples.

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

12 Jul 2010 Erdal Bizkevelci  
13 Jul 2010 Luis Lacerda

hello, i have read the examples but i still can´t answer my question...how 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..

thanks

Please login to add a comment or rating.
Updates
29 Jul 2009

Fixed typos, added a contents.m file.

04 Aug 2009

Added 3 GUIs, expanded suggested exercises.

10 Aug 2009

User suggestions and correction have been incorporated.

27 Oct 2009

Fixed typos and inconsistencies due to user feedback.

27 Jan 2010

6 more examples added. Also an HTML version of contents is included.

Tag Activity for this File
Tag Applied By Date/Time
gui Matt Fig 28 Jul 2009 10:58:13
example Matt Fig 28 Jul 2009 10:58:13
files Matt Fig 28 Jul 2009 10:58:13
guide Matt Fig 28 Jul 2009 10:58:13
how to Matt Fig 17 Aug 2009 22:39:21
learn Matt Fig 17 Aug 2009 22:39:21
learning Matt Fig 17 Aug 2009 22:39:21
help Matt Fig 17 Aug 2009 22:39:21
tips Matt Fig 17 Aug 2009 22:39:39
example Bill 19 Aug 2009 21:28:43
example mario 21 Aug 2009 14:19:59
example Bjørn Helge Østerås 24 Aug 2009 07:43:55
files Aman P.V 30 Sep 2009 14:39:55
gui Paulo 07 Oct 2009 09:05:52
example Goran 20 Oct 2009 21:01:49
example ILIYA 22 Oct 2009 14:24:45
example Niccolo' Bulgarini 29 Oct 2009 10:13:59
example Gushter Hodzic 16 Nov 2009 13:47:46
gui wee 25 Nov 2009 03:50:51
example jose paniagua 16 Dec 2009 21:14:40
example Frantisek 22 Dec 2009 10:56:22
files Frantisek 22 Dec 2009 10:56:28
gui John 10 Feb 2010 15:07:23
potw Shari Freedman 12 Feb 2010 10:56:20
example Ashok 16 Feb 2010 07:27:15
example Peter Lo 18 Feb 2010 15:25:35
example Shoukat Choudhury 28 Feb 2010 11:40:30
gui Ryan 15 Mar 2010 23:56:04
example marwa saad 04 May 2010 07:04:47
gui Felice Andrea 09 May 2010 13:52:23
example sule yucel 26 May 2010 04:22:15
example Les Peterson 26 May 2010 09:46:59
example Andreas 27 May 2010 16:03:13
example Michael 01 Jun 2010 17:16:45
files John D 10 Jun 2010 08:42:50
gui kuoping 27 Jun 2010 23:50:08
example Mounir 28 Jun 2010 07:34:06
gui William Pinto 15 Jul 2010 11:02:10
guide William Pinto 15 Jul 2010 11:02:18

Contact us at files@mathworks.com