Skip to Main Content Skip to Search
Product Documentation

setdiff - Returns difference between two vectors of Simulink.WorkspaceVar objects

Syntax

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

Description

VarsOut = setdiff (VarsIn1, VarsIn2) inputs two vectors of Simulink.WorkspaceVar objects and returns a vector containing a Simulink.WorkspaceVar 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 returnes 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.WorkspaceVar.setdiff) and gives identical results

Input Arguments

VarsIn1

A vector of Simulink.WorkspaceVar objects

VarsIn2

Another vector of Simulink.WorkspaceVar objects

Output Arguments

VarsOut

A vector of Simulink.WorkspaceVar 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.WorkspaceVar(who);
used_vars = Simulink.findVars(models, 'WorkspaceType', 'base');
unusedVars = setdiff(base_vars, used_vars);

See Also

intersect | setdiff | Simulink.findVars

How To

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS