MATLAB: How to find all the base workspace variables of a certain type that are referenced in a model

simulink

I want to get a list of all the base workspace variables of a certain type that are referenced in a model. I have tried using "Simulink.findVars", but there is not option to specify the data type or class. How can I get a list of only Simulink.Parameter objects that are referenced by my model?

Best Answer

You can retrieve the entire list of variables using "Simulink.findVars" and then construct another list based on what class of variables you are looking for. See the following example:
allVars = Simulink.findVars(modelName, 'SourceType', 'base workspace');
myVars = Simulink.VariableUsage;
myVars(1) = '';
desiredClass = 'Simulink.Parameter';
for i = 1:length(allVars)
    tmp = evalin('base',allVars(i).Name);
    if strcmp(class(tmp),desiredClass)
        myVars(end+1) = allVars(i);
    end
end
The resulting list of Simulink.Parameter objects will be found in "myVars"