MATLAB: How to list the different variants of a block library in Simulink 7.5 (R2010a)

simulink

I have a Model block and would like to list all the model reference variants I have previously defined in the associated library.

Best Answer

The different variants of a block can be listed as follows:
% Replace BlockName with the actual block name
modrefblock = find_system(gcs, 'Name', 'BlockName');
% Variants is a cell array containing a structure
variants = get_param(modrefblock, 'Variants');
% Variantnames is a cell array with the names of all variants
variantnames = {variants{1}.ModelName};
The first command is retrieving the handle to the model block in the Simulink model. With the second command, all the variants of the model are returned as a cell array. If you only need to retrieve the names, you can consider extracting just the first field of the previously obtained structure.
All the fields of the structure can be listed with:
disp(variants{1})