1
1
0
1
0
0
Similarly, you can compare one of the arrays to a scalar.
A > 7
ans =
0
0
0
1
1
1
If you compare a 1-by-N row vector to an M-by-1 column vector, then MATLAB expands each vector
into an M-by-N matrix before performing the comparison. The resulting matrix contains the
comparison result for each combination of elements in the vectors.
A = 1:3
A =
1
2
3
B = [2; 3]
B =
2
3
A >= B
ans =
0
1
1
0
0
1
Empty Arrays
The relational operators work with arrays for which any dimension has size zero, as long as both
arrays have compatible sizes. This means that if one array has a dimension size of zero, then the size
of the corresponding dimension in the other array must be 1 or zero, and the size of that dimension in
the output is zero.
A = ones(3,0);
B = ones(3,1);
A == B
ans =
Empty matrix: 3-by-0
However, expressions such as
A == []
return an error if A is not 0-by-0 or 1-by-1. This behavior is consistent with that of all other binary
operators, such as +, -, >, <, &, |, and so on.
To test for empty arrays, use isempty(A).
2 Program Components
2-30
1
0
1
0
0
Similarly, you can compare one of the arrays to a scalar.
A > 7
ans =
0
0
0
1
1
1
If you compare a 1-by-N row vector to an M-by-1 column vector, then MATLAB expands each vector
into an M-by-N matrix before performing the comparison. The resulting matrix contains the
comparison result for each combination of elements in the vectors.
A = 1:3
A =
1
2
3
B = [2; 3]
B =
2
3
A >= B
ans =
0
1
1
0
0
1
Empty Arrays
The relational operators work with arrays for which any dimension has size zero, as long as both
arrays have compatible sizes. This means that if one array has a dimension size of zero, then the size
of the corresponding dimension in the other array must be 1 or zero, and the size of that dimension in
the output is zero.
A = ones(3,0);
B = ones(3,1);
A == B
ans =
Empty matrix: 3-by-0
However, expressions such as
A == []
return an error if A is not 0-by-0 or 1-by-1. This behavior is consistent with that of all other binary
operators, such as +, -, >, <, &, |, and so on.
To test for empty arrays, use isempty(A).
2 Program Components
2-30
