How do I change the parameters of a MATLAB Function Block during simulation?

1 次查看(过去 30 天)
I have a matlab function block (lets call it block.m) and it has 1 input and 2 parameters attached to it. The parameters to the block are loaded from the base workspace. I want to change the parameter values at each simulation. How do I do it?

回答(1 个)

Pavan Sahith
Pavan Sahith 2023-10-12
Hi Aswin,
I understand you have a MATLAB Function block with 1 input and 2 parameters, and you want to change the parameter values at the start of each simulation.
If they are being fetched from the base workspace at start of each simulation, you can change their values using the ‘InitFcn’ callback in the Model Properties under the Model Settings which can be found under the MODELING tab in Simulink.
To ensure that your parameters are being loaded from the base workspace, you can utilize 'Model Explorer' to determine the workspace in which they are located and refer to the 'Symbols Pane' to confirm their type as 'Parameter Data' , by looking under the same MODELING tab.
If you want to change the value of parameters inside the MATLAB function, the variable in the base workspace do not get updated.
You can also refer to this similar MATLAB answers question for more understanding-https://in.mathworks.com/matlabcentral/answers/776747

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by