Using parsim with SIMULINK model containing c-mex s-functions
6 visualizzazioni (ultimi 30 giorni)
I have a simulation with multiple S-functions (level 2 written in c++). I want to run a Monte-Carlo analysis for my problem and to speed up the process, I want to run the simulations in parallel using the parsim command. There's a parameter for the S-functions "DX" which would be different for every simulation.
model = 'my_model';
numSims = 10;
for i = 1:numSims
in(i) = Simulink.SimulationInput(model);
in(i) = in(i).setVariable('DX',my_data(:,i));
simOut = parsim(in);
According to my understanding, this should work but it gives me errors.
My c++ S-functions is supposed to load and read some DAT files in order to run and they are in a different folder. The path to access the files is written inside the code. I have added an exception in the code that it should give error "Data could not be loaded" in case the code fails to load and read the files. I get this error when I try to run the simulation using "parsim" command. However, it works fine using the "sim" command.
What could I be doing wrong here? Am I missing something? Any help would be highly appreciated.
Benjamin Thompson il 14 Feb 2022
Alternatively, you can read data from a binary file using fopen and fread in an M file in MATLAB. Read each dataset into the MATLAB workspace and use a Simulink foreach subsystem to pass data to the sin function in Simulink.