I want to use a timer to read the data from a simulink block to the workspace during simulation. I made a simple mdl model composed of a clock connected to a scope. Then I wrote this simple code:
t=timer('period', 1, 'taskstoexecute', 10, 'executionmode', 'fixedrate');
t.Timerfcn={@TimeStep};
start(t)
function time = TimeStep (~,~)
load_system('mymodel');
set_param('mymodel','SimulationCommand','start');
block='mymodel/Clock';
rto=get_param(block,'runtimeObject');
time=rto.OutputPort(1).Data;
disp(time);
The problem is that when I run the code for simulation time 10, it shows me "0" in work space and repeat it ten times. I assume that it should show me the time from 1 to 10. I have also modifies the solver to a discrete solver with time step=1. The other thing I do not understand is that when I put a ramp function instead of the clock and change it to: block='mymodel/Ramp';'
then I receive an error of "too many inputs". I would appreciate any help.