Path: news.mathworks.com!not-for-mail
From: "Vihang Patil" <vihang_patil@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: timer and gui edit
Date: Sat, 12 Apr 2008 06:21:02 +0000 (UTC)
Organization: Konem Solutions
Lines: 55
Message-ID: <ftpkce$n7r$1@fred.mathworks.com>
References: <ftoi5e$pm6$1@fred.mathworks.com>
Reply-To: "Vihang Patil" <vihang_patil@yahoo.com>
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 1207981262 23803 172.30.248.38 (12 Apr 2008 06:21:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 12 Apr 2008 06:21:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 413701
Xref: news.mathworks.com comp.soft-sys.matlab:462544



"Alessandro C." <a.cocciola@gmail.com> wrote in message 
<ftoi5e$pm6$1@fred.mathworks.com>...
> Hi all
> 
> This is my code:
> 
> a = 1;
> while a == 1
>     t = timer('TimerFcn', 'y = myfunction(x)');
>     start(t)
>     pause(2)
> end
> 
> I would like to show the y value in a edit object every 2
> seconds. How can I do it?
> 
> Thank you in advance
> 
> Alessandro
> 

Hello
Define your timer function and start the timer in the 
gui_openingfcn if you want the timer to start as soon as 
the gui is loaded or you can define the timer function in 
the gui_openingfcn() but start the timer only say after 
the pushbutton is pressed. 
You dont need the while loop at all as the timer function 
will the job for you. 
Try this;

function main_gui_OpeningFcn(hObject, eventdata, handles, 
varargin)
handles.guifig = gcf;
handles.tmr = timer('TimerFcn', 
{@TmrFcn,handles.guifig},'BusyMode','Queue',...
    'ExecutionMode','FixedRate','Period',2);%timer 
updating after every 2 secs
guidata(handles.guifig,handles);

start(handles.tmr);
guidata(hObject, handles);

%Timer Function
function TmrFcn(src,event,handles) %Timer function
handles = guidata(handles);
x = myfunction(y);%define your function here 
set(handles.edit1,'String',num2str(x)); %assuming x is 
type 'double'
guidata(handles.guifig, handles);

HTH
Vihang