In most OO languages, where variables can point to objects, they can also have a null value, which is very convenient.
In Matlab, I have a function that parses a command and then returns an array of cells or false (which is zero - this is another common pattern) if it fails:
function re = parse(s) ... if (invalid) re = false; return; end end
The problem is that when I check the result, it gives an error:
re = parse(s); if (false == re) Undefined function 'eq' for input arguments of type 'cell'.
I wrote a function for checking without errors: strcmp('logical', class(re)) && false == re , but it seems very slow to use in hot areas of the code, and also inconvenient if I need to add this function to each file M I am writing.
Using NaN even worse because, in addition to throwing this error, it is also not equal to itself.
What is the best alternative to use with this template?
source share