Path: news.mathworks.com!not-for-mail
From: "Adam Bright" <abc_services_2000@yahoo.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: gui problem
Date: Mon, 14 Apr 2008 22:26:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 274
Message-ID: <fu0llq$iu6$1@fred.mathworks.com>
Reply-To: "Adam Bright" <abc_services_2000@yahoo.co.uk>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208211962 19398 172.30.248.35 (14 Apr 2008 22:26:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 14 Apr 2008 22:26:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1142958
Xref: news.mathworks.com comp.soft-sys.matlab:462941


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.

my code is the following:
function varargout = gui(varargin)
% GUI M-file for gui.fig
%      GUI, by itself, creates a new GUI or raises the existing
%      singleton*.
%
%      H = GUI returns the handle to a new GUI or the handle to
%      the existing singleton*.
%
%      GUI('CALLBACK',hObject,eventData,handles,...) calls
the local
%      function named CALLBACK in GUI.M with the given input
arguments.
%
%      GUI('Property','Value',...) creates a new GUI or
raises the
%      existing singleton*.  Starting from the left,
property value pairs are
%      applied to the GUI before gui_OpeningFunction gets
called.  An
%      unrecognized property name or invalid value makes
property application
%      stop.  All inputs are passed to gui_OpeningFcn via
varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI
allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui

% Last Modified by GUIDE v2.5 31-Mar-2008 12:06:04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State,
varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

% End initialization code - DO NOT EDIT


% --- 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);
% Choose default command line output for gui
handles.output = hObject;
set(hObject,'toolbar','figure');
% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command
line.
function varargout = gui_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see
VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Graph1.
function Graph1_Callback(hObject, eventdata, handles)
% hObject    handle to Graph1 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1)


%If statement to convert pressure into volume
case1 = (pressure < 995.7);
case2 = (pressure >= 995.7 & pressure < 1149.2);
case3 = (pressure >= 1149.2);
volume = zeros(size(pressure));
volume(case1) = ((pressure(case1)-442.95)*5.365);
volume(case2) = ((pressure(case2)-749.29)*12.034);
volume(case3) = ((pressure(case3)-934.08)*22.371);

cumvol = volume;
for i = 2:length(cumvol), if cumvol(i) < cumvol(i-1)
cumvol(i) = cumvol(i-1); end, end

zerovol = (cumvol - (cumvol(1,1)));
%values = 3000 * (ones(size(zerovol)));
runoff = zerovol / 3000; 

cumrain = cumsum(raininput);

%5 minute rain values 
cumrain5 = cumrain(1:5:end);
runoff5 = runoff(1:5:end);
%Discretised values for cumrain and runoff

d = 2:length(cumrain5);
disccumrain = (cumrain5(d)) - (cumrain5(d-1));

e = 2:length(runoff5);
discrunoff = (runoff5(e)) - (runoff5(e-1));


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


[AX,H1,H2] =
plotyy(timeplot5,disccumrain,timeplot5,discrunoff,'bar'); 
set(gcf, 'color', 'white');
set(H1,'BarWidth',0.4,...
  'EdgeColor',[0 0.749 0.749],...
  'FaceColor',[0 0.749 0.749],...
  'LineStyle','--') 
set(H2,'BarWidth',0.4,...
  'EdgeColor',[0.6824 0.4667 0],...
  'FaceColor',[0.6824 0.4667 0],...
  'LineStyle',':') 
set(AX(2),'YLim',[0 1])
set(AX(1),'YLim',[0 1])
set(AX(1),'YTick',[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1])
set(AX(2),'YTick',[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1])
set(get(AX(1),'Ylabel'),'String','Rainfall (mm)') 
set(get(AX(2),'Ylabel'),'String','Surface Runoff (mm)') 
title('Surface Runoff from green roof with rainfall
comparison');
xlabel('Time');
datetick(AX(1),'x',15)
datetick(AX(2),'x',15)
%datetick(AX(1),'x','dd-mmm-yyyy HH:MM:SS')
%datetick(AX(2),'x','dd-mmm-yyyy HH:MM:SS')
%datetick(AX(1),'x',13)
%datetick(AX(2),'x',13)
guidata(hObject, handles);

% --- Executes on button press in Graph2.
function Graph2_Callback(hObject, eventdata, handles)
% hObject    handle to Graph2 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in Graph3.
function Graph3_Callback(hObject, eventdata, handles)
% hObject    handle to Graph3 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox1
contents as cell array
%        contents{get(hObject,'Value')} returns selected
item from listbox1

start_date = get(handles.listbox1,'Value')
guidata(hObject, handles);
% --- Executes during object creation, after setting all
properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    empty - handles not created until after all
CreateFcns called

% Hint: listbox controls usually have a white background on
Windows.
%       See ISPC and COMPUTER.
set(handles.listbox1,'String',time)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
guidata(hObject, handles);

% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject    handle to listbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox2
contents as cell array
%        contents{get(hObject,'Value')} returns selected
item from listbox2


end_date = get(handles.listbox2,'Value');
% --- Executes during object creation, after setting all
properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    empty - handles not created until after all
CreateFcns called

% Hint: listbox controls usually have a white background on
Windows.
%       See ISPC and COMPUTER.

set(handles.listbox2,'String',time)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in ClearGraph.
function ClearGraph_Callback(hObject, eventdata, handles)
% hObject    handle to ClearGraph (see GCBO)
% eventdata  reserved - to be defined in a future version of
MATLAB
% handles    structure with handles and user data (see GUIDATA)
cla(handles.axes1,'reset')
guidata(hObject, handles);

thankyou for your help