MATLAB: Rapid Accelerator Simulation

simulation

I am running a simulation on bunch of differnt matfiles. My model can indvidually run in Rapid Accelerator mode but I can not figure out a way to run the whole sim in a for loop simulating each matfile….WITHOUT BUILDING RAPID ACCELETOR EACH TIME.
Here is how my code looks like
for i=1:100
filename = filelist(i)
load(filename) %This one loads, 11 (say V1 to V11) variables from the file into Matlab workspace
Process data, create time vector and initialize simulink variable
mdl = 'Mymodel.mdl'
sim(mdl,'SimulationMode', 'rapid')
end
so in this example, my code will build rapid accelerator target every single time for each loaded file (100 times). Which consumes lots of time.
I tried using,
if (i == 1)
load_system(mdl);
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
sim(mdl,'SimulationMode', 'rapid');
else
sim(mdl,'SimulationMode', 'rapid','RapidAcceleratorUpToDateCheck','off');
end
Here it builds rapid accelerator target only for the first time, but for all subsequent runs, it uses the exact model that it built from (first loaded model + workspace) and my workspace variables dont get assigned to model every time Basically all my 100 runs produce same results.
My question is…. Is there any way to assign new variables from workspace to already built simulation target model and run the sim in for loop?
paramName = {'V1', 'V2', 'V3',...'V11'}
paramValue = {Cspeed, CTemp, Cflow,...,Cvar };
sim(mdl, paramName, paramValue,'SimulationMode', 'rapid','RapidAcceleratorUpToDateCheck','off')
(In my sim model, there is one input block where I assign all the 11 loaded workspace variable to 11 simulink blocks)

Best Answer

You can only change tunable parameters after the rapid accelerator target has been built. You can figure out if a parameter is tunable or non-tunable by looking at the parameter attributes list that can be obtained using get_param(gcb, 'DialogParameters'). This command returns a structure with the block parameter names as fields. Each field further is a structure that has an "Attributes" field. The list of attributes will contain 'read-only-if-compiled' for non-tunable parameters.