MATLAB: How to run 2 simulink models in a sequential manner from .m script in a loop

MATLABsimulink

Actually, I have 2 simulink models in which the first model's outputs are used as input for the next model. I have used 'to' and 'from' blocks to connect one model's outputs with other. The issue is that since they are run in a loop, the workspace is not getting updated. Due to this thing, the from blocks in the 2nd model cannot read the outputs from the first model. How to overcome this issue? (Please check the attached files)

Best Answer

Do the following:
Open your first model, go to File->Model Properties->Model Properties->Callback->StopFcn and type
a=1;
then from command line, type the following:
sim('firstmodel.slx');
if a==1
sim('secondmodel.slx');
end
Hope this helps. Let me know the results.