MATLAB: Is an empty string not empty? isempty(”) returns true, but isempty(“”) returns false

emptyMATLABstring

(Updated to clarify the problem)
Strings, added in R2016b, are a great addition to matlab, but one aspect is a problem: testing for empty variables with isempty() no longer gives a consistent response.
>> isempty('')
ans =
logical
1
>> isempty("")
ans =
logical
0
% even though comparison for equality is 'true':
>> '' == ""
ans =
logical
1
One would expect that if the two values are considered equal, that a builtin function like isempty() would produce the same result.
Presumably "" is not empty because it is a string object, while '' really is the same as [ ]. But this is a problem for code that tests for empty character input using isempty(…). It no longer works as expected if passed "" instead of ''. Is there a switch we can turn on or off to enable isempty("") to return true?
A function written prior to R2016b never needed to check for empty "" (double-quoted) strings, because Matlab would throw an exception if passed something in double quotes. Now, that code produces incorrect results if a user passes in an empty double-quoted string.
One can, of course, test using strlength(…)==0, but IIRC, the Matlab IDE gave a warning about efficiency for this, and recommended using isempty(…).

Best Answer

There have been many good suggestions above for workarounds for code going forward. Thanks all for your input. Having read and synthesized everyone's input, here are my (hopefully final) thoughts.
First, it seems that there are no perfect solutions here. On one hand, Cobeldick is right that changing isempty("") to return true would produce problems for someone who needs "" to not be empty; on the other hand, there is a huge codebase out there, including mine, which tests for empty strings with isempty(...) and which did not anticipate the introduction into matlab of string objects for which isempty("") would return false. That code base now is broken, and I and many others now need to update our code.
For my own part, I am going back through all my code and replacing all calls to isempty(...) with a call to a new function that returns the proper answer for my needs, and putting that function in a folder which is in the search path for all code I write.
In case it helps others, here is that function:
function tf = isempty_s(x)
tf = isempty(x) || (isstring(x) && length(x) == 1 && strlength(x)==0);
end