Get and Set the Parameters of MATLAB Simulink Blocks using Script

Dec. 11, 2023

In MATLAB, users can use the script to set parameters and then run the Simulink model. Specifically, we could use set_param1 to set the parameters of Simulink blocks (correspondingly, use get_param2 to get current parameter values) and run the model by sim3 function. However, if we want to use set_param and get_param functions, we must exactly specify the parameter name. And I have to say, it is kind of hard to find them, because these parameter names are not given in their corresponding official documentations. But luckily, the parameter names of all Simulink blocks are listed together and can be found in web pages “Common Block Properties”4 and “Block-Specific Parameters”5.

Added on February 29, 2024.

In practice, we don’t need to look up the aforementioned documentation5 every time, instead we could use get_param function2 to get all parameter names by inputting "ObjectParameters" property6:

1
get_param(block_name,"ObjectParameters")

which returns a structure listing all model parameters, or

1
fieldnames(get_param(block_name,"ObjectParameters"))

which returns a cell array that only contains the model parameter names.


References