MATLAB Answers


Use of Simulink Signal Logging and SimScape Logs with Parallel

Asked by Jack
on 10 Apr 2012


I've recently started using the Parallel Computing Toolbox for running parallel simulations in Simulink (including SimScape). Previously I was utilising the Simulink signal logging option and SimScape logging option to log simulation data to two log objects (nominally logsout for Simulink and simlog for SimScape). The examples, including a demo model, for parallel simulations in Simulink only seem to show how to extract the model output and time trace ( yout and tout) from the workers. I cannot figure out how to extract the simulations logs from the workers. I imagine there is a way to route all signal data to the model output, and extract the data from there, however my model is multi-domain with a significant amount of physical modelling blocks (SimHydraulics) and I would like to be able to access the Simulink and SimScape logs from parallel runs.

Can anybody help me with this issue?





No products are associated with this question.

2 Answers

Answer by Guy Rouleau
on 10 Apr 2012
 Accepted answer

The following documentation page explain how to use the Single-Output Syntax for the sim Command:

This single-output syntax has been designed especially for calling SIM within PARFOR.

using that, you will call sim:

SimOut = sim('model', 'ReturnWorkspaceOutputs', 'on');

and everything will be stored in simOut. If logging both "logsout" for Simulink signals and and "simlog" for Simscape, you will be able to extract the data with a syntax like:

myVar1 = simOut.get('logsout'); myVar2 = simOut.get('simlog');


Guy Rouleau
on 23 Apr 2012

I am sorry. I just realized there is a problem with the Simscape "simlog". It is not included in the single-output. To get it, you should be able to execute this line just after SIM:

simlogs{idx} = evalin('base', 'simlog');

on 9 Jul 2012

Is there a way to save simlog to a file like a mat file? This is not related to using the parallel toolbox but this seems like the right place to ask this question. Thanks, Aditya

on 10 Jul 2012

If you get no answers, you could post this as a new question so that it is more likely to be seen.

Answer by K E
on 10 Apr 2012

I am sure there is a better approach, but a workaround would be to save a mat file containing each simulation's results. This could be done using a Matlab script to run the set of simulations; outputting desired simulation results to the Workspace using the To Workspace block; choosing a distinct mat file name within the Matlab script; and saving the mat file. A post-processing script could load all the mat files, for example to plot engine temperature vs. motor constant (if that was what was varying across the simulations). As a cheat with no Parallel toolbox, prior to each simulation create the uniquely named mat file that will contain the results, for example saving some dummy information. Then do not run the simulation if the file already exists. This allows several concurrent sessions of matlab/simulation to work through the set of simulations.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!