Thread Subject: timer and gui edit

Subject: timer and gui edit

From: Alessandro C.

Date: 11 Apr, 2008 20:37:02

Message: 1 of 4

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

Subject: timer and gui edit

From: Vihang Patil

Date: 12 Apr, 2008 06:21:02

Message: 2 of 4

"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


Subject: timer and gui edit

From: Alessandro C.

Date: 14 Apr, 2008 10:17:01

Message: 3 of 4

Thank you very much Vihang!

Your code works perfectly.

Thanks again for your time.

Alessandro

Subject: timer and gui edit

From: Jerzy Lapa

Date: 18 Apr, 2009 09:54:01

Message: 4 of 4

"Vihang Patil" <vihang_patil@yahoo.com> wrote in message <ftpkce$n7r$1@fred.mathworks.com>...
> "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
>
>

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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
timer Vihang Patil 12 Apr, 2008 02:25:06
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com