Main Content

intersect

Return intersection of two arrays ofSimulink.VariableUsage对象

Description

example

VarsOut= intersect(VarsIn1,VarsIn2)returns an array that identifies the variables described inVarsIn1and inVarsIn2, which are arrays ofSimulink.VariableUsage对象. If a variable is described by aSimulink.VariableUsageobject inVarsIn1and inVarsIn2, the function returns aSimulink.VariableUsageobject that stores the variable usage information from both objects in theUsersproperty.

intersectcompares theName,Source, andSourceTypeproperties of theSimulink.VariableUsage对象inVarsIn1with the same properties of the objects inVarsIn2. IfVarsIn1andVarsIn2each containSimulink.VariableUsage对象that have the same values for these three properties, they both describe the same variable.

To createSimulink.VariableUsage对象that describe the usage of variables in a model, use theSimulink.findVarsfunction.

Examples

collapse all

Given two models, discover the variables needed by both models.

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

Input Arguments

collapse all

First array of variables for comparison, specified as an array ofSimulink.VariableUsage对象.

Second array of variables for comparison, specified as an array ofSimulink.VariableUsage对象.

Output Arguments

collapse all

Variables that are described in both input arrays, returned as an array ofSimulink.VariableUsage对象. The function returns an object for each variable that is described inVarsIn1and inVarsIn2.

Introduced in R2012b