Exporting simulink data during simulation

Hi,

I have to export the Simulink output data of the Fast model in “real-time” but I don’t know how to do it! Can anyone help me? If iI use the “To Workspace” block I can export the data only when the simulation ends but I want them for each time step.

I tried to write this in Matlab as i found on internet :

% Run Simulink
load_system=(‘FatigueControl’);
set_param(‘FatigueControl’,‘SimulationCommand’,‘Start’);

% Export real time data from Simulink
block=‘FatigueControl/Clock’;
rto=get_param(block, ‘RuntimeObject’);
time= rto.OutputPort(1).Data;

But it only works to export the first time value!

Thank you!