>
Greater-than operator: tests element by element whether A is larger than B.
Category: Language Fundamentals > Operators and Elementary Operations
Syntax
C = A > B
Applies the operator to A and B. Same as gt(A, B).
Description
The comparison is element-wise with implicit expansion and returns a logical array. It is typically used to build conditions, to count with sum(x > t), or to filter with x(x > t). Comparisons with NaN are always 0.
Inside if and while, an array condition is true only when all its elements are nonzero.
Input arguments
A, B- Numeric, logical or char arrays (only the real part is compared for complex values). Sizes must be compatible, or one of them a scalar.
Output arguments
C- Logical array:
1where the relation holds,0elsewhere.
Example
x = [4 -1 7 0];
x > 0
sum(x > 0)
x(x > 0)
Output
ans = 1×4 logical array
1 0 1 0
ans = 2
ans = 1×2
4 7