Main Content

setdiff

Return difference between two arrays of Simulink.VariableUsage objects

Description

VarsOut = setdiff(VarsIn1,VarsIn2) returns an array that identifies the variables described in VarsIn1 but not in VarsIn2, which are arrays of Simulink.VariableUsage objects. If a variable is described by a Simulink.VariableUsage object in VarsIn1 but not in VarsIn2, the function returns a copy of the object.

setdiff compares the Name, Source, SourceType, and Users properties of the Simulink.VariableUsage objects in VarsIn1 with the same properties of the objects in VarsIn2. If VarsIn1 and VarsIn2 each contain a Simulink.VariableUsage object with the same values for these three properties, the objects describe the same variable, and setdiff does not return an object to describe it.

To create Simulink.VariableUsage objects that describe the usage of variables in a model, use the Simulink.findVars function.

Examples

collapse all

Given two models, discover the variables that are needed by the first model but not the second model.

model1Vars = Simulink.findVars('model1');
model2Vars = Simulink.findVars('model2');
differentVars = setdiff(model1Vars,model2Vars);

Locate all variables in the base workspace that are not used by a loaded model that has been recently compiled.

models = find_system('type','block_diagram','LibraryType','None');
base_vars = Simulink.VariableUsage(who,'base workspace');
used_vars = Simulink.findVars(models,'WorkspaceType','base');
unusedVars = setdiff(base_vars,used_vars);

Input Arguments

collapse all

First array of variables for comparison, specified as an array of Simulink.VariableUsage objects.

Second array of variables for comparison, specified as an array of Simulink.VariableUsage objects.

Output Arguments

collapse all

Variables that are described in the first input array but not in the second input array, returned as an array of Simulink.VariableUsage objects. The function returns an object for each variable that is described in VarsIn1 but not in VarsIn2.

Version History

Introduced in R2012b