What Does It Mean?

Basically, it means using MATLAB scripts to control, configure and simulate Simulink models without clicking through the GUI.

So, why is it important in automotive model-based development?

It is very useful for tasks like automated test execution, batch parameter tuning, SIL and HIL setups, generating reports and regression testing.

In automotive model-based development (MBD) is useful for:

  • Automated test execution
  • Batch parameter tuning
  • SIL (Software-in-the-Loop) and HIL (Hardware-in-the-Loop) setups
  • Generating reports and regression testing

Some key capabilities are:

  • Load, open, save and close models
  • Read and modify block parameters
  • Add or delete blocks/lines programmatically
  • Run simulations and collect outputs
  • Automate test cases or create simulation dashboards

Model Management Commands

Now, let’s understand some basic model management commands in Simulink.

Example:

model = 'engine_model';
load_system(model);
open_system(model);
save_system(model);
close_system(model);

Getting & Setting Block Parameters

Use get_param() and set_param() for controlling block properties. Basically, get_param() is used to read block properties, and set_param() is used to change them.

Get Parameter:

gainVal = get_param('engine_model/Gain', 'Gain');

Set Parameter:

set_param('engine_model/Gain', 'Gain', '5');

Adding/Deleting Blocks and Connections

Let’s understand how to adding and deleting blocks and connections in Simulink.
Add a Block:

add_block('simulink/Commonly Used Blocks/Constant', ...
'engine_model/SpeedInput', 'Position', [100 100 140 120]);

Output

Delete a Block:

delete_block('engine_model/SpeedInput');

Delete Connection:

delete_line('engine_model', 'SpeedInput/1', 'Gain/1');

Running Simulations Programmatically

Using sim() function:

simOut = sim('engine_model', 'StopTime', '10');

Handling Outputs:

data = simOut.get('yout'); % Get logged output data

Batch Simulation Example:

for k = 1:5
assignin('base', 'input_gain', k); % Set variable in base workspace
sim('engine_model'); % Run simulation
end

Automating via Scripts

Now let’s understand how we can automate tasks in Simulink using scripts. Why do we think automation is important?

So, to save time and avoid doing the same steps again and again automate tasks in Simulink is important. For example, if we want to change test inputs, we can use commands like set_param or assignin.

Also we can use a for loop with sim(). By this way, we can simulate the model for different parameter values automatically.

When we run a simulation, the output is stored in a variable like simOut. we can retrieve logged signals using:

simOut.get('logsout')

We can combine sim(), plotting functions like plot(), and saving figures with saveas(). By this way, we can generate reports automatically. So, with scripts, we can create a full workflow from running tests to preparing results.

That’s why scripting is important to model-based development.


Automotive Use Cases

Let’s understand what we learned with automotive use cases. Do we know where programmatic Simulink access is applied in the industry?

It is basically used in testing. For example, in MIL and SIL testing, engineers use sim() in loops to batch simulate different model variants.

Similarly parameter tuning is used to sweep values, like gains or lookup table data, across ranges using scripts. That helps find the best calibration.

Another test automation is used in test suites where we can be scripted to run multiple cases and check pass or fail conditions automatically.

So how we can relate this to ECU coding, Basically before generating code with Embedded Coder, we can automate pre-processing steps, such as adjusting configurations or setting parameters.

We can even script dashboards. For example, by using add_block(), we can dynamically build models or create visual test environments.

So these commands are not just for learning, but directly applied in real automotive workflows and they save time, reduce errors and make large projects manageable.