Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

timer and gui edit

699 views
Skip to first unread message

Alessandro C.

unread,
Apr 11, 2008, 4:37:02 PM4/11/08
to
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

Vihang Patil

unread,
Apr 12, 2008, 2:21:02 AM4/12/08
to
"Alessandro C." <a.coc...@gmail.com> wrote in message
<ftoi5e$pm6$1...@fred.mathworks.com>...

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


Alessandro C.

unread,
Apr 14, 2008, 6:17:01 AM4/14/08
to
Thank you very much Vihang!

Your code works perfectly.

Thanks again for your time.

Alessandro

Jerzy Lapa

unread,
Apr 18, 2009, 5:54:01 AM4/18/09
to
"Vihang Patil" <vihang...@yahoo.com> wrote in message <ftpkce$n7r$1...@fred.mathworks.com>...

Hi, i'm new here.
I must make GUI with timer and yours example works perfectly but only with Edit boxes and I need updating Axes too. In my GUI it opens figure1 in each Timerfcn.


function TmrFcn(src,event,handles) %Timer function

handles = guidata(handles);
axes(handles.axes1);
hold off
bar([2,1],'r');
guidata(handles.output, handles);

what's wrong? i must use set?

Thx for your help.
Jurek

Lina Carmen

unread,
Feb 8, 2011, 10:20:07 PM2/8/11
to
Hi,I was going to ask the same question,but I wont after I see your reply.
Its great,thanks.


"Vihang Patil" <vihang...@yahoo.com> wrote in message <ftpkce$n7r$1...@fred.mathworks.com>...

>

0 new messages