3

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

Tunaki
  • 132,869
  • 46
  • 340
  • 423

1 Answers1

2

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:

Mask Editor

Then in the workspace, enter Simulink.Parameters 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:

Enter Mask Data

Then when you right click to turn into an S-Function, you'll get:

RTW Screen

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.

macduff
  • 4,655
  • 18
  • 29
  • First of all thank you. Almost got it. y.mdl needs 47 input parameters calculated by x.m. Those parameters are in the Workspace. Every time I run x.m those parameters are going to be different. "Everything I need to do is making y.exe input parameters loaded from the workspace." Any clue? Thanks – John McEnroe Mar 05 '12 at 16:26
  • Works. tic-toc results: No S-function = 1.1596 sec. S-function = 0.3666 sec. Thank you very much. – John McEnroe Mar 06 '12 at 08:18