# HG changeset patch # User Jaroslav Hajek # Date 1245390397 -7200 # Node ID 6c255e51ef7edda687ef5a0f1bca811a44c98e11 # Parent da465c405d849d37651a9b9d08e1ef94cf6720e9 improve & fix ismember diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-06-19 Jaroslav Hajek + + * set/ismember.m: Properly handle NaNs. Fix test. + 2009-06-18 Ben Abbott * plot/__go_draw_axes__.m: Change the default x11 fontspec from '*,0' diff --git a/scripts/set/ismember.m b/scripts/set/ismember.m --- a/scripts/set/ismember.m +++ b/scripts/set/ismember.m @@ -97,15 +97,32 @@ else [s, is] = sort (s); endif + + ## sort out NaNs + if (isreal (s) && ! isempty (s) && isnan (s(end))) + s = s(1:end - sum (isnan (s))); + endif + if (isreal (a)) + anan = isnan (a); + a(anan) = 0; + endif + if (nargout > 1) a_idx = lookup (s, a, "m"); tf = logical (a_idx); if (! isempty (is)) a_idx(tf) = is (a_idx(tf)); endif + if (isreal (a)) + tf(anan) = false; + a_idx(anan) = 0; + endif else tf = lookup (s, a, "b"); + if (isreal (a)) + tf(anan) = false; + endif endif elseif (nargin == 3 && strcmpi (rows_opt, "rows")) @@ -200,7 +217,7 @@ %!test %! [result, a_idx] = ismember ("1.1", "0123456789.1"); -%! assert (all (result == logical ([1, 1, 1])) && all (a_idx == [2, 11, 2])); +%! assert (all (result == logical ([1, 1, 1])) && all (a_idx == [12, 11, 12])); %!test %! [result, a_idx] = ismember([1:3; 5:7; 4:6], [0:2; 1:3; 2:4; 3:5; 4:6], 'rows');