From: us on 21 Dec 2008 08:22 "Ashwini Deshpande" > > > 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 > 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 while evaluating TimerFcn for timer 'timer-1' yes, the snippet was meant to be used in the command window (copy/paste or a simple script) to show a crude sequence of commands, which do what you want - including the fact that the command string COM uses the var SH (instead of UD(1)), which only is valid in this context... now, if you want to place the idea into a function, this might be a solution function tmsg(varargin) % - add options by employing the VARARGIN args in your function, eg, % - period, message box title, and so on... % the messagebox mh=msgbox('foo','timing...'); % - handle to its text obj sh=findobj(mh,'tag','MessageBox'); % the timer th=timer(... 'executionmode','fixedrate',... 'period',1,... 'timerfcn',{@tcb,sh,clock}); start(th); uiwait(mh,10); stop(th); delete(th); if ishandle(mh) close(mh); end end % timer callback function function tcb(this,dummy,mhdl,clk) %#ok set(mhdl,'string',round(etime(clock,clk))); end us
From: Ashwini Deshpande on 22 Dec 2008 02:06
"us " <us(a)neurol.unizh.ch> wrote in message <gilftq$s7a$1(a)fred.mathworks.com>... > "Ashwini Deshpande" > > > > 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 > > > 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 while evaluating TimerFcn for timer 'timer-1' > > yes, the snippet was meant to be used in the command window (copy/paste or a simple script) to show a crude sequence of commands, which do what you want - including the fact that the command string COM uses the var SH (instead of UD(1)), which only is valid in this context... > > now, if you want to place the idea into a function, this might be a solution > > function tmsg(varargin) > % - add options by employing the VARARGIN args in your function, eg, > % - period, message box title, and so on... > % the messagebox > mh=msgbox('foo','timing...'); > % - handle to its text obj > sh=findobj(mh,'tag','MessageBox'); > % the timer > th=timer(... > 'executionmode','fixedrate',... > 'period',1,... > 'timerfcn',{@tcb,sh,clock}); > start(th); > uiwait(mh,10); > stop(th); > delete(th); > if ishandle(mh) > close(mh); > end > end > % timer callback function > function tcb(this,dummy,mhdl,clk) %#ok > set(mhdl,'string',round(etime(clock,clk))); > end > > us Thank u very much ..... |