Reputation: 33
Right now, I have a x.m file that runs a y.mdl model using sim('y') command. Solver parameters from y.mdl cannot be changed and all the elements in the model are mandatory. There are no diagnostics warnings. Everything is running smoothly The output of the model is a value (no parameters change in time, no scopes...). Just a double value. I do not even need to open the model. Question: Is there any way to improve the performance of x.m?
Thanks in advance,
John
Upvotes: 3
Views: 2105
Reputation: 4685
If all that is required is to execute the model via the sim
command, I would say that this would be a candidate to generate an S-function. If you have the Real Time Workshop toolbox, you can right click on the top-level subsystem, select Real-Time Workshop
and then Generate S-Function
. This will generate an S-Function model, which you can save as a library and use in your y.mdl
file to substitute for your top level block. This method will generate and compile C-code which will execute much faster than the original model.
If you need to initialize certain parameters, you can use the Simulink mask and Simulink.Parameter
. First, create the subsystem that you want to simulate. Then mask the subsystem by right clicking on the subsystem and hit, Mask Subsystem
. Any parameter you want to modify needs to be mapped to the mask. So, if you have 3 variables in your model, a
, b
, and c
. In the mask editor hit the parameters tab and enter data similar to the following:
Then in the workspace, enter Simulink.Parameter
s for your variables:
a_var = Simulink.Parameter;
a_var.Value = 42;
b_var = Simulink.Parameter;
b_var.Value = 4;
c_var = Simulink.Parameter;
c_var.Value = 2;
Of course, whatever value you need is fine, scalar, array, matrix, etc. Then enter these variable names into the subsystem mask:
Then when you right click to turn into an S-Function, you'll get:
Check all of them to be tunable. Then when you run your script, before you start simulation initialize the variables in the workspace like so:
evalin('base','a_var.Value = 22')
That's not my favorite method, but it works. Hopefully, this will get you where you need to go.
Upvotes: 2