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

4 次查看(过去 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,12:57
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