timer function is not executing the function i am providing ,please help me with this?
10 views (last 30 days)
Steven Lord on 10 Jun 2019
This attempts to call the ritik function with 0 input arguments and 1 output argument and use the output argument from that call as the TimerFcn for the timer being created on this line. But your ritik function cannot return any output arguments, so MATLAB throws an error.
If you want MATLAB to call ritik as the TimerFcn for the timer specify it as a function handle.
However, as stated in the "Creating Callback Functions" section on this documentation page, "When you create a callback function, the first two arguments must be a handle to the timer object and an event structure." Your ritik function does not accept any input arguments, and so does not satisfy the requirements imposed upon a TimerFcn by the timer object. You could use an anonymous function as an "adapter" (see the table in the "Specifying the Value of Callback Function Properties" on the documentation page I linked above) to bridge the gap between the signature the timer object expects its TimerFcn to have and the signature your ritik function actually has.
But looking more closely at your ritik function, I'm not sure what exactly you're trying to do with your timer. It won't have access to the global variable t (and I strongly recommend avoiding global variables!) and all it does is try to start and stop the timer repeatedly.
If you explain why you're trying to use a timer in this situation we may be able to help you achieve that goal.