MATLAB: Ismember 0×0 empty logical array to logic

ismember

Hi All,
I have an array "A = [1 2 3 4 5 6]" which its length reduces in a loop
if ~ismember(A,ID)
do this
else
do that
end
This works fine until the A=[], which ismember returns
0×0 empty logical array
However I need a Single Value and not logical array. Note that I cannot use any and all functions to reduce Logical Arrays to Single Value, beacuse I faced with other problems when "A" array is not yet empty!
How can I fix this problem?

Best Answer

The obvious answer would seem to be to test
if isempty(A) || ~ismember(A,ID)
If you were hoping there were a hidden preference you could set that would make ismember(A,ID) return a non-empty value without having to change your test.. sorry, there is no such test.
I would point out that you could also rewrite your code:
if ismember(A,ID)
do that
else
do this
end
the ismember() would be empty when A is empty, so the test would fail, and do that would not be done, leaving you to fall through to the do this case.