Resulting Model Workspace when using Simulink InputObject

36 ビュー (過去 30 日間)
Gunter Nitzsche
Gunter Nitzsche 2025 年 1 月 23 日 5:18
コメント済み: Gunter Nitzsche 2025 年 1 月 23 日 6:37
Hello,
I am currently playing around in using the model workspace in Simulink and overwriting some of the variables via the Simulink InputObject. But I am facing an issue: How do I know what I simulated in the end. E.g. I would like to put the value of certain parameters in the figures I programatically generate. Or I simply would like to store the parameter set alongside the simulation results.
So the question is: How can I retrieve the resulting state of the model workspace, when using a Simulink InputObject when simulating with the sim command?
I mean I could make sure, that the InputObject provides values for all the variables in the model workspace. This way I could retrieve the state from the InputObject or the source, which feeds the InputObject. But then I would loose the flexibility to relay on default values stored in the model workspace itself.
Thank you for your help in advance.

回答 (1 件)

Akshat Dalal
Akshat Dalal 2025 年 1 月 23 日 6:20
Hi Gunter,
You can create a 'Simulink.ModelWorkspace' Object to interact with the model workspace of a model programmatically. You can access it before and after the simulation to get default and updated simulation results as necessary. You can use the 'getVariable' API to get the value of any variable. Please find more information on the documentation links below:
Thanks
  1 件のコメント
Gunter Nitzsche
Gunter Nitzsche 2025 年 1 月 23 日 6:37
Thank you for your answer. But I think this is not working for me.
  1. I could change my parameter via the Simulink.ModelWorkspace Object I could use also assignin to change the value inside the model workspace. But this would be registered as change to the model and would trigger a save request, when closing and would than also be considered a change by source control. I don't want this, because I do not want to change the default values stored in the model workspace.
  2. When using the Simulink.SimulationInput Object when calling sim, the variables are applied temporarily to the workspace and are reverted back afterwards. Thus, I cannot retrieve the variable values with the Simulink.ModelWorkspace afterwards. I even tried to access the Simulink.ModelWorkspace in the InitFcn or StartFcn or StopFcn callbacks of the model. But they all just report the default value when checking the model workspace via ws = get_param(modelName, 'ModelWorkspace');.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by