First, I tried,
t = timer('TimerFcn','InfoUpdate
(handles)','ExecutionMode','fixedRate','Period',10);
% where InfoUpdate(handles) is a function declared in the
same .m file.
The warning was "undefined variable or
function 'handles'". Someone told me TimerFcn executes in
the base Matlab workspace, so it can't find function
defined inside '...'.
Then I tried
t = timer('TimerFcn',
{@InfoUpdate,handles},'ExecutionMode','fixedRate','Period',
10);
% where InfoUpdate(handles) is a function declared in the
same .m file
The warning was "too many input argument for TimerFcn".
But when I implemented InfoUpdate(handles) alone, it ran
well and no error occured.
The 'handles' parameter is required in my GUI .m file, and
can't be avoid using.
So how can I pass the parameter 'handles' into TimerFcn?
Thank you~
Matlab automatically passes extra arguments to callback
functions, namely the callback object and an
object-dependent data structure. All user-specified args are
passed as additional ags, following the default callback
args. To see which args are passed in actuality:
1. modify your callback function signature as follows:
function InfoUpdate(varargin)
2. Now place a breakpoint on the first line of this function
using the editor or the dbstop() function
3. Now run your code and check varargin - it will contain
all the actual args passed by Matlab in run-time
4. Finally, modify your callback function's signature based
on what you found in step 3.
Note: I could have given you the correct function signature
but then you & other readers would not be able to solve
similar problems for other callbacks - the methodology above
gives a general-purpose way to solve this kind of problem.
Yair Altman
http://ymasoftware.com
JK Wang
Specifically,
what do you mean by change the function's signature?
> 3. Now run your code and check varargin - it will contain
> all the actual args passed by Matlab in run-time
>
> 4. Finally, modify your callback function's signature based
> on what you found in step 3.
"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message <fg9kro$4oh$1...@fred.mathworks.com>...