It is possible to override the logical operators like '>' (greater than) and '<' (less than) in MATLAB. When applying a logical operator MATLAB looks for an M-function with a specific name corresponding to the operation defined for an object of the class being compared (in this case, the class would be double). To overload the built-in function, create a custom function, named gt.m (to overload >) in a @double directory on the MATLAB path. This file will then be called with two inputs when MATLAB executes a statement like
Steps:
1. First, for accepting double input variables, create a folder named: "@double" (without quotes)
2. Inside this directory, create a file named "gt.m" and input the following code:
function C = gt(A,B)
if any(isnan([A B]))
else
end
3. Now edit the MATLAB path to bring the folder in which @double folder exists, at the top most level
4. Verify if your gt.m is ahead of the others by executing :
at the MATLAB command prompt and check if the folder containg @double appears before the built-in gt.m files
5. Now restart MATLAB and execute the following to check if the code works fine:
6. Similarly, if you wish, you can override the following files as well:
lt ('<'), le ('<='), ne ('!='), eq ('==')
Best Answer