hasSymType
Tests whether an expression contains a subexpression of a given symbolic type.
Category: Symbolic Computations in MATLAB > Symbolic Variables, Expressions, Functions, and Preferences
Syntax
tf = hasSymType(S, type)
Returns true if any subexpression of S has the type type.
Description
The search covers the entire expression tree. That is why hasSymType(x^2, 'integer') is true: the exponent 2 is an integer subexpression, even though the expression as a whole is not an integer.
It is the yes-or-no counterpart of findSymType, and unlike isSymType it looks inside the expression rather than at its top level.
Input arguments
S- Symbolic expression.
type- Type name string, such as
'variable','integer'or a function name like'sin'.
Output arguments
tf- Logical scalar.
Example
Searching by type
syms x
hasSymType(x^2, 'variable')
hasSymType(x^2, 'integer')
hasSymType(x^2, 'sin')
hasSymType(sin(x) + 1, 'sin')
Output
ans = logical
1
ans = logical
1
ans = logical
0
ans = logical
1