Code covered by the BSD License  

Highlights from
GUI Examples using Nested Functions

3.86667

3.9 | 15 ratings Rate this file 60 Downloads (last 30 days) File Size: 3.55 KB File ID: #7301

GUI Examples using Nested Functions

by Steven Lord

 

28 Mar 2005 (Updated 30 Mar 2005)

These two examples demonstrate how to use nested functions to reduce parameter passing in GUIs.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

These two examples, which were originally posted in the MATLAB newsgroup comp.soft-sys.matlab, demonstrate how to use the nested function capability of MATLAB 7.0 (R14) and later versions to reduce the number of parameters that need to be passed into and between callbacks inside a GUI M-file. Each nested function in one of these examples is contained in its own cell; if you enable cell mode in the MATLAB Editor and place the cursor in a given nested function, you will be able to see where each nested function begins and ends. Each example is extensively commented and indicates when variables from a parent function's workspace are being used by a nested function.

To execute these examples, simply unzip the ZIP file and place the contents in a directory on your MATLAB path, then execute "red_blue" or "red_blue_two" without the quotes at the MATLAB prompt.

For more information on nested functions, please check the Programming section of the MATLAB documentation.

NOTE: These examples will only function using MATLAB 7.0 (R14) and later. Versions of MATLAB prior to 7.0 did not have the ability to nest functions and you will receive an error about an undefined function or variable 'red' if you try to use it in earlier versions.

Acknowledgements
This submission has inspired the following:
Simple Examples How Create gui-applications
MATLAB release MATLAB 7 (R14)
Other requirements These examples will only function using MATLAB 7.0 (R14) and later.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
30 Mar 2005 Brett Shoelson

Very nice illustration of nested functions.

30 Mar 2005 navid barati  
25 May 2005 rohit singh  
31 Jul 2005 Mark Wolschon

Easy to follow.

02 Aug 2005 Sanith Varkey - CTS

error in the programm

02 Aug 2005 Sinoy Xavier

Some error in both programms

02 Aug 2005 Schreier Manfred  
29 Sep 2005 heson chang  
23 Apr 2006 Quintin Coetzee  
10 Jul 2006 kazim abbas

nice

26 Aug 2006 Jake Bromage

Ahh... another reason why I need to understand nested functions! I was slowly getting used to GUIDE's handles structure but was finding it to be very unsatisfying. This is much more elegant.

Steven: Thank you for taking the time. Nice job.

05 Sep 2006 FG FG  
05 Mar 2007 sayed saad  
28 May 2007 FARID FARIDI  
04 Feb 2009 Cedric Gommes

Fine example, Steven.
 
How can I pass a value to an argument out of the function red_blue?

For instance, I would like to be able to call the function as COLOR=red_blue() in another code, and get for COLOR whatever color I choose by clicking.
 

31 Oct 2009 Ashwini

Good One .!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
gui tools Steven Lord 22 Oct 2008 07:44:28
example Steven Lord 22 Oct 2008 07:44:28
red_blue Steven Lord 22 Oct 2008 07:44:28
red_blue_two Steven Lord 22 Oct 2008 07:44:28
nested function Steven Lord 22 Oct 2008 07:44:28
newsgroup Steven Lord 22 Oct 2008 07:44:28
example Sumedhe 04 May 2010 15:27:41
example Parth Modh 09 Dec 2010 12:36:32
example Kannan 21 Jun 2011 01:39:21
example John Umap 16 Jul 2011 02:39:56
example Greg 26 Jul 2011 20:02:54
example Elia Edna 05 Aug 2011 11:24:57

Contact us at files@mathworks.com