You can use MATLAB timers in this way :
Set execution mode of the timer object to fixedRate, fixedDelay or fixedSpacing to execute your call back repeatedly
set(t,'executionMode','fixedRate');
Specify the function handle or the command you want to be executed. In your case, for sending messages over a ROS topic , use send : set(t,'TimerFcn','send(pub,msg)');
Set the frequency or period(in seconds),at which the timer callback function is called
set(t,'Period', 0.02);
start(t);
ROS message msg is then sent periodically(every 0.02 seconds). To stop the timer:
Delete the timer object after usage
Best Answer