Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matlab - what is the equivalent of null / None / nil / NULL etc.?

Tags:

matlab

In most OO languages, where variables may point to objects, they may also have a null value, which is highly convenient.

In Matlab, I have a function which parses a command, and then returns a cell array, or false (which is equal to zero — which 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've written a function to check it without an error: strcmp('logical', class(re)) && false == re, but that seems to be really slow for use in hot areas of the code, and also inconvenient if I have to add this function to every M file I'm writing.

Using NaN is even worse, because besides throwing that error, it also isn't equal to itself.

What's a better alternative for use with this pattern?

like image 550
Evgeni Sergeev Avatar asked Mar 14 '13 04:03

Evgeni Sergeev


People also ask

Does Matlab have null?

Use the null function to calculate orthonormal and rational basis vectors for the null space of a matrix. The null space of a matrix contains vectors x that satisfy Ax = 0 .

Is nil the same as null?

NULL and nil are equal to each other, but nil is an object value while NULL is a generic pointer value ((void*)0, to be specific). [NSNull null] is an object that's meant to stand in for nil in situations where nil isn't allowed. For example, you can't have a nil value in an NSArray.

How do you represent null in Matlab?

null (MATLAB Functions) Z = null(A) is an orthonormal basis for the null space of A obtained from the singular value decomposition. That is, A*Z has negligible elements, size(Z,2) is the nullity of A , and Z'*Z = I .

Is nil the same as null Ruby?

Let's start out with “Nil” since it's the most common and easy-to-understand way of representing nothingness in Ruby. In terms of what it means, Nil is exactly the same thing as null in other languages.


1 Answers

You can use the isequal function to compare any two items without causing that error. For example:

if isequal (re, false)
    %code here
end
like image 53
Pursuit Avatar answered Oct 03 '22 18:10

Pursuit