<= comparison in matlab

To perform the less-than or equal to comparison in MATLAB you can use the <= operator. It operates element-wise on arrays with the same size, and returns an array of logical 1 (true) where the relation is true and 0 (false) where it is not.

Example:

main.m
a = [1, 3, 5, 7];
b = [3, 3, 1, 7];
c = a <= b;
48 chars
4 lines

In this example, c is the result of the element-wise comparison between arrays a and b. The result is:

main.m
c =
  1  1  0  1
17 chars
3 lines

since 1 <= 3, 3 <= 3, 5 is not <= 1, and 7 <= 7.

related categories

gistlibby LogSnag