Using too many input arguments for timer function
Show older comments
Hi, I have a simulink model with a source that outputs varying values with time (like a sinusoidal source). These values are to be displayed in a static text field in a MATLAB GUI. I plan to implement this using a timer function as follows:
function a = test
a = timer('ExecutionMode','fixedRate','Period',10,'TimerFcn',@simulate_link);
start(a);
wherein the simulate_link function is defined as:
function simulate_link()
sim('Simulink_model');
g_x = gyroscope_x;
set(handles.gyro_x,'String',num2str(g_x));
further, this timer goes into the callback of a toggle button
function Start_stop_Callback(hObject, eventdata, handles)
my_timer = test();
However, upon running the script that includes these functions, I get this error: "Error while evaluating TimerFcn for timer 'timer-3'. Too many input arguments."
I read the documentation for the timer function, and I can't figure out which is the "extra argument" I have used here.
Please guide!
Answers (1)
Walter Roberson
on 13 Jun 2018
Just like nearly every other callback in MATLAB, there are automatically two parameters supplied by MATLAB. The first one is the object whose callback it is, and the second one is information about the cause of the callback.
If you are not interested in the information, you still need to have your timer function accept them -- you are not required to pay attention to them.
function simulate_link(~, ~)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!