Simulink 'To Workspace' Block variable change in a Matlab script

7 views (last 30 days)
Jan Kramer
Jan Kramer on 1 Mar 2021
Answered: Rhea Chandy on 4 Mar 2021
Hello, I have a Simulink model that is dependent on a parameter. Now I would like to change this parameter in a "loop function" and record a new data series in the workspace for each run. The problem is in the "to Workspace" block I cannot overwrite the variable via matlab script. Is there a command for this or another way of how I record data series to which a variable is assigned during the "loop function"?
Thank you in advance, Jan

Answers (1)

Rhea Chandy
Rhea Chandy on 4 Mar 2021
Hi Jan,
From what I understand, you need to find a way to change a variable parameter in a simulink model programmatically, but you're not able to overwrite the variable.
It may be that when you use the "To Workspace" block, the variable parameter is being saved into the model workspace rather than in the base workspace. This may be the reason you're not able to overwrite the variable via matlab script. More data about working with Model Workpaces is here: Model Workspaces
Another reason could be that If you are using the sim MATLAB function, the To Workspace block sends data to the workspace of the calling function, not to the MATLAB base workspace. The base workspace stores variables that are written at the command line. More info on the difference between the workspaces and how to share data between the workspaces, can be found here : Base and Function Workspaces

Community Treasure Hunt

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

Start Hunting!

Translated by