parsim: Create SimulinkInput Object from currently open model with initial values

Technical Source
2 min readSep 22, 2021

I am trying to parallelize a large number of Simulink simulations for a Monte Carlo study on a multicore Machine using parsim.

The Help on parsim details, that one has to create a “SimulinkInput object” for each simulation that will run in parsim.

I have my model set up for calculation, initial values and other external values loaded into the model.

What I do not understand is: How can I generate the SimulinkInput Object from my currently open Simulink model? Especially: Without looping over all Input values that are loaded in “from Workspace” blocks? (they are also initial values for my ode)

Currently I run my simulations in nested for loops over all the parameters that change during the study but I think of running the loop for all possible combinations, create the SimulinkInput object for each set of data and afterwards run everything in parallel using parsim, avoiding the nested loops. Is this even possible?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

If I understand correctly you have a lot of variables and inputs in the base workspace, some of these variables change from run to run while others remain constant. Currently you have nested for loops to iterate over all possible combinations and Im guessing you are calling sim() in the deepest nested for loop?

Based on that understanding, I think the best way to transition your code to use parsim is to keep your nested for loops but instead of calling sim() instead use setVariable() on the SimulationInput object for only the variables that are changing from run to run. For all variables in the base workspace that are the same from run-to-run, you can leave those in the base workspace (no need to attach them directly to the SimuationInput object) and then transfer the base workspace to the workers with the “TransferBaseWorkspaceVariables” option on parsim.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.