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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

Samayochita
Samayochita il 13 Ago 2025
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.

Categorie

Scopri di più su Manage Variant Modeling Components in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by