Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: gui problem
Date: Mon, 14 Apr 2008 22:52:04 -0400
Organization: The MathWorks, Inc.
Lines: 72
Message-ID: <fu1595$gvf$1@fred.mathworks.com>
References: <fu0llq$iu6$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1208227941 17391 144.212.105.187 (15 Apr 2008 02:52:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 15 Apr 2008 02:52:21 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:462971



"Adam Bright" <abc_services_2000@yahoo.co.uk> wrote in message 
news:fu0llq$iu6$1@fred.mathworks.com...
> Hi I've been trying to make a listbox which contains the
> information from an array; this will then be used as the
> start point for the graoh which i'm producing.At the moment
> the script i have is using the whole range which is in the
> array and is producing the graph ok. However now that i'm
> trying to make the listbox work, it says "Undefined function
> or variable 'time'"
>
> However, the time array does exist otherwise it would be
> impossible for the graph to show.When I type the array
> 'time' in the workspace, it says the same thing,so i dont
> understand   how its possible that the array is being used
> to perform the graph but the array is showing to produce the
> listbox.

Each function has its own workspace, where variables that are created inside 
the function live until the function ends, at which point they are 
destroyed.  In your OpeningFcn:

*snip*

> % --- Executes just before gui is made visible.
> function gui_OpeningFcn(hObject, eventdata, handles, varargin)
> % This function has no output args, see OutputFcn.
> % hObject    handle to figure
> % eventdata  reserved - to be defined in a future version of
> MATLAB
> % handles    structure with handles and user data (see GUIDATA)
> % varargin   command line arguments to gui (see VARARGIN)
> %Assinging Variables
> [time,number,pressure,raininput] =
> textread('staticvirginia.txt','%s %d %f
> %f','delimiter',',','headerlines',4);

*snip*

you create the variable 'time' here, and it exists until:

*snip*

> % UIWAIT makes gui wait for user response (see UIRESUME)
> % uiwait(handles.figure1);

the end of your OpeningFcn, at which point it Goes Away.  Later on, in your 
Graph1_Callback function:

*snip*

> %Graph Plotting Information
> timeplot = datenum(time, '"yyyy-mm-dd HH:MM:SS"');

you're using time before you create it in this function.

There are a number of ways to share data between functions in a GUI.  Take a 
look at this page from the documentation for descriptions of the different 
methods:

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f13-998449.html

For more general information about functions, scripts, and workspaces, read 
this documentation page:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f7-38085.html

-- 
Steve Lord
slord@mathworks.com