change active variant subsystem name from a script in matlab

You can use the setActiveConfigSet method of the Simulink.BlockDiagram class to change the active variant subsystem for a model from a MATLAB script. Here's an example code snippet:

main.m
% Load the model
model = 'mySimulinkModel';
load_system(model);

% Set the active variant subsystem
variantSubsystem = 'myVariantSubsystem';
configSet = getActiveConfigSet(model);
variantConfig = getconfigset(model, ['ConfigSet/Configurations/' variantSubsystem]);
setActiveConfigSet(configSet, variantConfig);

% Save the changes
save_system(model);
351 chars
13 lines

In this example, replace 'mySimulinkModel' with the name of your Simulink model, and replace 'myVariantSubsystem' with the name of the variant subsystem that you want to make active. After running this script, the active variant subsystem for the model will be the one named 'myVariantSubsystem'.

related categories

gistlibby LogSnag