changeset 15332:aaf938d17e0c

Verify appdata exists before removing a propery. Also verify the property exists before removing it. Bug # 39720 * scripts/miscellaneous/rmappdata.m: Validate appdata exists before removing a field. Validate the field exists before removing it. * scripts/plot/private/__go_draw_axes__.m: Correcgt spelling; "ploty" > "plotyy"
author Philip Nienhuis <philipnienhuis>
date Fri, 07 Sep 2012 21:34:10 -0400
parents 81cc4e5733b1
children b613757ff5be
files scripts/miscellaneous/rmappdata.m scripts/plot/private/__go_draw_axes__.m
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/rmappdata.m
+++ b/scripts/miscellaneous/rmappdata.m
@@ -30,16 +30,30 @@
   endif
 
   for nh = 1:numel (h)
-    appdata = get (h(nh), "__appdata__");
-    appdata = rmfield (appdata, varargin);
-    set (h(nh), "__appdata__", appdata);
+    if (isprop (h(nh), "__appdata__"))
+      appdata = get (h(nh), "__appdata__");
+      for v = 1:numel(varargin)
+        if (isfield (appdata, varargin{v}))
+          appdata = rmfield (appdata, varargin{v});
+        else
+          error ("rmappdata: appdata '%s' is not present")
+        endif
+      endfor
+      set (h(nh), "__appdata__", appdata);
+    endif
   endfor
 
 endfunction
 
-
 %!test
 %! setappdata (0, "hello", "world");
 %! rmappdata (0, "hello");
 %! assert (isappdata (0, "hello"), false);
 
+%!test
+%! setappdata (0, "data1", rand (3));
+%! setappdata (0, "data2", {"hello", "world"});
+%! rmappdata (0, "data1", "data2");
+%! assert (isappdata (0, "data1"), false);
+%! assert (isappdata (0, "data2"), false);
+
--- a/scripts/plot/private/__go_draw_axes__.m
+++ b/scripts/plot/private/__go_draw_axes__.m
@@ -47,7 +47,7 @@
       else
         h = axis_obj.__plotyy_axes__;
         h = h(ishandle (h));
-        h = h(isprop (h, "__ploty_axes__"));
+        h = h(isprop (h, "__plotyy_axes__"));
         rmappdata (h, "__plotyy_axes__");
       endif
     endif