From: Ashwini Deshpande on
Hi,

Is it possible to display clock on MSgbox window??
(I want to start a countdown timer which start from 0 upto 30 sec, as time elapses it has to be shown on msgbox)

If yes, how do i do it ??

Any ideas ??

Regards,
Ashwini

From: us on
"Ashwini Deshpande"
> Is it possible to display clock on MSgbox window??
> (I want to start a countdown timer which start from 0 upto 30 sec, as time elapses it has to be shown on msgbox)...

one of the solutions

% the message
mh=msgbox('foo');
sh=findobj(mh,'tag','MessageBox');
% the timer
% - callback sequence
com=[
'ud=get(th,''userdata'');',...
'if ishandle(ud(1));',...
'set(sh,''string'',etime(clock,ud(2:end)));'...
'else;',...
'stop(th);',...
'end'
];
th=timer(...
'executionmode','fixedrate',...
'period',1,...
'timerfcn',com,...
'userdata',[sh,clock]);
start(th);
% - running for 10 seconds
% - or until the OK button is pressed
uiwait(mh,10);
stop(th);
delete(th);
if ishandle(mh)
close(mh);
end

us
From: Ashwini Deshpande on
"us " <us(a)neurol.unizh.ch> wrote in message <gifeo0$e3f$1(a)fred.mathworks.com>...
> "Ashwini Deshpande"
> > Is it possible to display clock on MSgbox window??
> > (I want to start a countdown timer which start from 0 upto 30 sec, as time elapses it has to be shown on msgbox)...
>
> one of the solutions
>
> % the message
> mh=msgbox('foo');
> sh=findobj(mh,'tag','MessageBox');
> % the timer
> % - callback sequence
> com=[
> 'ud=get(th,''userdata'');',...
> 'if ishandle(ud(1));',...
> 'set(sh,''string'',etime(clock,ud(2:end)));'...
> 'else;',...
> 'stop(th);',...
> 'end'
> ];
> th=timer(...
> 'executionmode','fixedrate',...
> 'period',1,...
> 'timerfcn',com,...
> 'userdata',[sh,clock]);
> start(th);
> % - running for 10 seconds
> % - or until the OK button is pressed
> uiwait(mh,10);
> stop(th);
> delete(th);
> if ishandle(mh)
> close(mh);
> end
>
> us

Thats great !!!!
Thank you very much ....

i didnot know that Timerfcn can also be defined in this way ...
Plz clarify one more thing, what is the significance of using findobj...?

With warm regards,
Ashwini

From: Ashwini Deshpande on
"Ashwini Deshpande" <vd.ashwini(a)mathworks.com> wrote in message <gig5j9$48k$1(a)fred.mathworks.com>...
> "us " <us(a)neurol.unizh.ch> wrote in message <gifeo0$e3f$1(a)fred.mathworks.com>...
> > "Ashwini Deshpande"
> > > Is it possible to display clock on MSgbox window??
> > > (I want to start a countdown timer which start from 0 upto 30 sec, as time elapses it has to be shown on msgbox)...
> >
> > one of the solutions
> >
> > % the message
> > mh=msgbox('foo');
> > sh=findobj(mh,'tag','MessageBox');
> > % the timer
> > % - callback sequence
> > com=[
> > 'ud=get(th,''userdata'');',...
> > 'if ishandle(ud(1));',...
> > 'set(sh,''string'',etime(clock,ud(2:end)));'...
> > 'else;',...
> > 'stop(th);',...
> > 'end'
> > ];
> > th=timer(...
> > 'executionmode','fixedrate',...
> > 'period',1,...
> > 'timerfcn',com,...
> > 'userdata',[sh,clock]);
> > start(th);
> > % - running for 10 seconds
> > % - or until the OK button is pressed
> > uiwait(mh,10);
> > stop(th);
> > delete(th);
> > if ishandle(mh)
> > close(mh);
> > end
> >
> > us
>
> Thats great !!!!
> Thank you very much ....
>
> i didnot know that Timerfcn can also be defined in this way ...
> Plz clarify one more thing, what is the significance of using findobj...?
>
> With warm regards,
> Ashwini


One more question ...

This code is working fine when i run it as a script file .. and gives the following error if i run it as a function,

error is:
??? Error while evaluating TimerFcn for timer 'timer-1'

Error using ==> timer.get at 46

Invalid timer object.
This object has been deleted and should be
removed from your workspace using CLEAR.

what do i do now??

Ashwini

From: Ashwini Deshpande on
"Ashwini Deshpande" <vd.ashwini(a)mathworks.com> wrote in message <gii10f$fkl$1(a)fred.mathworks.com>...
> "Ashwini Deshpande" <vd.ashwini(a)mathworks.com> wrote in message <gig5j9$48k$1(a)fred.mathworks.com>...
> > "us " <us(a)neurol.unizh.ch> wrote in message <gifeo0$e3f$1(a)fred.mathworks.com>...
> > > "Ashwini Deshpande"
> > > > Is it possible to display clock on MSgbox window??
> > > > (I want to start a countdown timer which start from 0 upto 30 sec, as time elapses it has to be shown on msgbox)...
> > >
> > > one of the solutions
> > >
> > > % the message
> > > mh=msgbox('foo');
> > > sh=findobj(mh,'tag','MessageBox');
> > > % the timer
> > > % - callback sequence
> > > com=[
> > > 'ud=get(th,''userdata'');',...
> > > 'if ishandle(ud(1));',...
> > > 'set(sh,''string'',etime(clock,ud(2:end)));'...
> > > 'else;',...
> > > 'stop(th);',...
> > > 'end'
> > > ];
> > > th=timer(...
> > > 'executionmode','fixedrate',...
> > > 'period',1,...
> > > 'timerfcn',com,...
> > > 'userdata',[sh,clock]);
> > > start(th);
> > > % - running for 10 seconds
> > > % - or until the OK button is pressed
> > > uiwait(mh,10);
> > > stop(th);
> > > delete(th);
> > > if ishandle(mh)
> > > close(mh);
> > > end
> > >
> > > us
> >
> > Thats great !!!!
> > Thank you very much ....
> >
> > i didnot know that Timerfcn can also be defined in this way ...
> > Plz clarify one more thing, what is the significance of using findobj...?
> >
> > With warm regards,
> > Ashwini
>
>
> One more question ...
>
> This code is working fine when i run it as a script file .. and gives the following error if i run it as a function,
>
> error is:
> ??? Error while evaluating TimerFcn for timer 'timer-1'
>
> Error using ==> timer.get at 46
>
> Invalid timer object.
> This object has been deleted and should be
> removed from your workspace using CLEAR.
>
> what do i do now??
>
> Ashwini


I got solution myself .......

Ashwini