If I do
ismember([NaN 0 3 2],[0 NaN])
then the output is
0 1 0 0
where I obviously expected
1 1 0 0
I tried
ismember(['3' 0 3 2],[0 '3'])
then the output is
1 1 0 0
How can I make ismember work for NaN?
Following with the convention that NaN ~= NaN
, ismember
treats NaN values as distinct. A quick shim that works for your given use case would be:
>> ismembernan = @(a,b) ismember(a,b) | (isnan(a) & any(isnan(b)));
>> a = [NaN 0 3 2];
>> b = [0 NaN];
>> ismembernan(a,b)
ans =
1 1 0 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With