changeset 16897:21d5e76891fe

Fix typo/bug for "-not" qualifier in findobj(). Add tests. * scripts/plot/findobj.m: The -not qualifier applies to the match which follows it.
author Ben Abbott <bpabbott@mac.com>
date Thu, 04 Jul 2013 19:05:59 -0400
parents b8c37a855074
children 531473481084
files scripts/plot/findobj.m
diffstat 1 files changed, 54 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/findobj.m	Thu Jul 04 07:54:28 2013 -0400
+++ b/scripts/plot/findobj.m	Thu Jul 04 19:05:59 2013 -0400
@@ -205,7 +205,7 @@
   keepers = ones (size (h));
   if (numpairs > 0)
     for nh = 1 : numel (h)
-      p = get (h (nh));
+      p = get (h(nh));
       for np = 1 : numpairs
         fields = fieldnames (p);
         fieldindex = find (strcmpi (fields, pname{np}), 1);
@@ -233,7 +233,7 @@
             match = all (match);
           endif
           if (strcmpi (logicaloperator{np}, "not"))
-            keepers(nh) = ! keepers(nh) & ! match;
+            keepers(nh) = keepers(nh) & ! match;
           else
             keepers(nh) = feval (logicaloperator{np}, keepers(nh), match);
           endif
@@ -291,11 +291,56 @@
 %! assert (h2, h1)
 
 %!test
+%! graphics_toolkit gnuplot;
 %! hf = figure ("visible", "off");
-%! h1 = subplot (2, 2, 1);
-%! h2 = subplot (2, 2, 2);
-%! h3 = subplot (2, 2, 3);
-%! h4 = subplot (2, 2, 4);
-%! userdata = struct ("foo", "bar");
-%! set (h3, "userdata", userdata);
-%! assert (findobj (hf, "userdata", userdata), h3)
+%! unwind_protect
+%!   h1 = subplot (2, 2, 1);
+%!   h2 = subplot (2, 2, 2);
+%!   h3 = subplot (2, 2, 3);
+%!   h4 = subplot (2, 2, 4);
+%!   userdata = struct ("foo", "bar");
+%!   set (h3, "userdata", userdata);
+%!   h = findobj (hf, "userdata", userdata);
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+%! assert (h, h3)
+
+%!test
+%! graphics_toolkit gnuplot;
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   h1 = subplot (2, 2, 1);
+%!   set (h1, 'tag', '1')
+%!   h2 = subplot (2, 2, 2);
+%!   set (h2, 'tag', '2')
+%!   h3 = subplot (2, 2, 3);
+%!   set (h3, 'tag', '3')
+%!   h4 = subplot (2, 2, 4);
+%!   set (h4, 'tag', '4')
+%!   drawnow ()
+%!   h = findobj (hf, 'type', 'axes', '-not', 'tag', '1');
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+%! assert (h, [h2; h3; h4])
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   h1 = subplot (2, 2, 1);
+%!   set (h1, 'userdata', struct ('column', 1, 'row', 1));
+%!   h2 = subplot (2, 2, 2);
+%!   set (h2, 'userdata', struct ('column', 2, 'row', 1));
+%!   h3 = subplot (2, 2, 3);
+%!   set (h3, 'userdata', struct ('column', 1, 'row', 2));
+%!   h4 = subplot (2, 2, 4);
+%!   set (h4, 'userdata', struct ('column', 2, 'row', 2));
+%!   drawnow ()
+%!   h = findobj (hf, 'type', 'axes', '-not', 'userdata', ...
+%!                struct ('column', 1, 'row', 1));
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+%! assert (h, [h2; h3; h4])
+