How can I load the control variables saved in a .mat file into the workspace without updating the Simulink model?

조회 수: 2 (최근 30일)
I have several control variables stored in a .mat file (Variant Configuration) that I would like to load into the workspace. When I load the Variant Configuration with "load ('Model_Configuration')" only the variant container is loaded into the workspace, not the included control variables.
When I update the model, the control variables are loaded into the workspace, but I would like to avoid that.
Is there a way to load the variable from the Variant Configuration directly into the workspace?

답변 (1개)

Samayochita
Samayochita 2025년 8월 13일
Hi Dominik Kurzmann,
I understand that you are trying to load the control variables from a Variant Configuration into the MATLAB workspace without updating the Simulink model.
You could push the control variables to your workspace without requiring a model update by following the steps mentioned below:
  1. On the Modeling tab, open the Design section and click Variant Manager.
  2. In the Configurations tab, scroll down to see the Control Variables section. The section shows the name of the currently selected variant configuration.
  3. Click on the “Export control variables to workspace(s)” button.
You could also achieve the same programmatically by following the steps given below:
  1. Get the variant configuration data object
varconfigdata = Simulink.VariantManager.getConfigurationData(modelname);
2. Retrieve a specific configuration
cfg = getConfiguration(varconfigdata, "LinInterExpNoNoise");
3. Check if ControlVariables exists, if yes extract control variables else throw an error.
if isstruct(cfg) && isfield(cfg, 'ControlVariables')
vars = cfg.ControlVariables;
Assign control variables to base workspace
for k = 1:numel(vars)
assignin('base', vars(k).Name, vars(k).Value);
end
Links to the relevant documentation:
Hope this helps.

카테고리

Help CenterFile Exchange에서 Manage Variant Modeling Components에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by