After some time I found a solution. First you start Simulink from Matlab:
set_param('Test_Simulink_Model','SimulationCommand','start')
Then you can pause the simulation after a step of time with a pulse generator and a Matlab function block.
Inside of the block is writen
function fcn(u)
coder.extrinsic('bdroot')
coder.extrinsic('set_param')
if u > 0
set_param(bdroot,'SimulationCommand','pause')
end
end
In the Matlab skript you can now ask if the simulation is paused.
if(strcmp(get_param('Test_Simulink_Model','SimulationStatus'), 'paused'))
Now you are able to read the values from the output blocks. For that you have to get the data from the 'RuntimeObject' of the block.
%Get all Vehicle variables
rto_s_x = get_param('Test_Simulink_Model/Read CM Dict','RuntimeObject');
s_x = rto_s_x.OutputPort(1).Data;
To wirte back the data you just calculated use
set_param('Test_Simulink_Model/Gas','Value',int2str(gas));
and to continue the simulation use
set_param('Test_Simulink_Model','SimulationCommand','continue')
To give Simulink a littel bit of time to start again you have to pause the Matlabloop for a shortening
pause(0.01)
If everything is done you can stop Simulink with
set_param('Test_Simulink_Model','SimulationCommand','stop')
I hope this will help the next one doing the same.
Regards, Kilian