Documentation Center

  • Trial Software
  • Product Updates

setdiff

Returns difference between two vectors of Simulink.VariableUsage objects

Syntax

VarsOut = setdiff (VarsIn1, VarsIn2)
VarsOut = VarsIn1.setdiff (VarsIn2)

Description

VarsOut = setdiff (VarsIn1, VarsIn2) inputs two vectors of Simulink.VariableUsage objects and returns a vector containing a Simulink.VariableUsage object for each workspace variable that is represented in the first vector but not the second. The function compares input objects by comparing their Name, Workspace, and WorkspaceType values. If all three value are the same in both objects, the two objects match. Any returned object is a new object having the same field values as the source input object.

VarsOut = VarsIn1.setdiff (VarsIn2) is the equivalent method syntax (Simulink.VariableUsage.setdiff) and gives identical results

Input Arguments

VarsIn1

A vector of Simulink.VariableUsage objects

VarsIn2

Another vector of Simulink.VariableUsage objects

Output Arguments

VarsOut

A vector of Simulink.VariableUsage objects containing a copy of any object in VarsIn1 that does not match any object in VarsIn2. Two objects match if their Name, Workspace, and WorkspaceType values are the same.

Examples

Given two models, discover which variables are needed by the first model but not the second model:

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

Locate all variables in the base workspace that are not being used by any recently-compiled open model:

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

See Also

| |

Was this topic helpful?