Path: news.mathworks.com!not-for-mail
From: "Bill " <millerwd@notes.udayton.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Nested Function Error?
Date: Fri, 17 Jul 2009 17:58:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 56
Message-ID: <h3qe39$7ks$1@fred.mathworks.com>
References: <h3okt9$bng$1@fred.mathworks.com> <h3p0tl$40m$1@fred.mathworks.com>
Reply-To: "Bill " <millerwd@notes.udayton.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1247853481 7836 172.30.248.38 (17 Jul 2009 17:58:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 17 Jul 2009 17:58:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1305913
Xref: news.mathworks.com comp.soft-sys.matlab:556341


Shan, the reason why I wanted KeyPressFcn in the while loop was because I'm trying to have a running timer in the GUI I am using. The problem is that while this clock is running, I need to be able to do other things, press other buttons, etc., and also at the same time be able to pause/stop the clock if need be. I not understand that I cannot nest GUI functions in a While Loop, but I am still without a solution. Currently, my solution, enclosed below works in terms of updating the clock, but fails to properly execute the stop and pause commands.

*********************************************************************
handles.ticFlag = 0;
handles.whileInitializer = 1;
handles.escapeFlag = 0;

function figure1_KeyPressFcn(hObject, eventdata, handles)
Key = get(gcf, 'CurrentKey');
handles.Key = Key;

switch(handles.Key)
    case 'f12' %%start key
        if handles.ticFlag == 0
            handles.startFlag = 1;
            handles.ticFlag = 1;
            beep;

            tic;
            while (handles.whileInitializer == 1) && (handles.escapeFlag ~= 1)
                handles.endTime = toc;
                handles.elapsedTime = handles.endTime;

                if handles.elapsedTime >= .1
                     %%In this section, I have code to parse out the seconds into minutes, etc. which I end up calling handles.displayedTime I didn't feel it necessary to include this.
                end
                set(handles.Timer, 'string', handles.displayedTime);
            

                drawnow;
                handles.Key=[];
            end

    case 'escape' %%Stop key
        if handles.escapeFlag == 0
            handles.whileInitializer = 0;
            handles.escapeFlag = 1;
            set(handles.Timer, 'string', 'Stopped');
            set(handles.Timer, 'ForegroundColor', [1 0 0]);
            guidata(hObject, handles);

            %%This will reset all settings back to the starting point.

        elseif handles.escapeFlag == 1
            handles.escapeFlag = 0;
            handles.pauseFlag = 0;
            set(handles.Timer, 'string', '00:00:00');
            set(handles.Timer, 'ForegroundColor', [1 1 0]);

            %%This will restart the program and restart all settings back to t=0
        end

etc...
*********************************************************************

I hope I explained it clearly. Basically, I want to ability to start and stop a timer that basically runs in the background of the GUI while I am able to do other things. I want the timer to be accessible, such as for whether or not I should modify things in the GUI, i.e. change the location of an axes over time, changes colors at certain times, etc.