Starting MATLAB 7.6(R2008a), you can use the function 'IsNull' to verify if a LIBPOINTER is pointing to a null reference.
For previous product releases, read below for any possible workarounds:
The ability to check directly whether a LIBPOINTER is null is not available in MATLAB 7.4 (R2007a) and previous releases. To work around this issue, try to retrieve the pointer's target in a TRY-CATCH block.
Attempting to dereference a null pointer will cause a MATLAB error of type "MATLAB:libpointer:ValueNotDefined". This error usually indicates a null pointer. You can use the following code to check for null pointers:
p = libpointer()
try
setdatatype(p, 'int8Ptr', 1, 80)
get(p)
catch
e = lasterror
if strcmp(e.identifier, 'MATLAB:libpointer:ValueNotDefined')
disp('Null pointer.')
end
end
get(p)
Best Answer