Illustration of logical built-in functions:
The function find returns the indices of a vector which meet certain criteria. For illustration, to find all the elements in a vector which are greater than 5:
>> vec = [5 3 6 7 2]
vec =
5 3 6 7 2
>> find(vec > 5)
ans =
3 4
The function is also equal and is useful in comparing the vectors. In MATLAB, using the equality operator with arrays will return 1 or 0 for every element; the all function could then be used on the resulting array to establish whether all elements were equal or not. The built-in function is equal and it also accomplishes this:
>> vec1 = [1 3 -4 2 99];
>> vec2 = [1 2 -4 3 99];
>> vec1 == vec2
ans =
1 0 1 0 1
>> all(vec1 == vec2)
ans =
0
>> isequal(vec1,vec2)
ans =
0