Exporting simulink data during simulation


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

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

But it only works to export the first time value!

Thank you!