Error using Timerfcn: too many input arguments

6 次查看(过去 30 天)
Hello. I created this timer
t = timer('Period', delay, 'TimerFcn', calculate(V, g, n, Vmin, Vmax));
which calls a function named "calculate"
function calculate
...
end
What's wrong with this code? Matlab returns this error message: ??? Error using ==> simulation>calculate Too many input arguments.

采纳的回答

Sean de Wolski
Sean de Wolski 2013-4-3
The Timerfcn is automatically passed two inputs, a handle to the timer and some event data.
In order to do what you have above (where you don't need either of the two given inputs) would be to use an anonymous function to absorb them:
t = timer('Period', delay, 'TimerFcn', @(~,~)calculate(V, g, n, Vmin, Vmax));
The '~' just ignores the input.
Also, your function calculate looks like it doesn't take any inputs. It would need to accept at least 5:
function calculate(V, g, n, Vmin, Vmax)
...
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Biological and Health Sciences 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by