changeset 27704:d30fcff9bad3

* hgload.m: Map "applicationdata" to "__appdata__" for Matlab compatibility (bug #57212).
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 16 Nov 2019 18:26:47 +0100
parents 12a53552db92
children 6c2a56c39c5d
files scripts/plot/util/hgload.m
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/hgload.m	Sat Nov 16 17:24:41 2019 +0100
+++ b/scripts/plot/util/hgload.m	Sat Nov 16 18:26:47 2019 +0100
@@ -64,12 +64,13 @@
   ## Load the handle structure
   hgs = {"s_oct40", "hgS_050200", "hgS_070000"};
   hg = load (filename);
-  i = isfield (hg, hgs);
-  if (nnz (i) == 1)
-    hg = hg.(hgs{i});
+  fig_file_version = isfield (hg, hgs);
+  if (nnz (fig_file_version) == 1)
+    hg = hg.(hgs{fig_file_version});
   else
     error ("hgload: could not load hgsave-formatted object in file %s", filename);
   endif
+  is_matlab_fig_file = any (fig_file_version(2:3));
 
   ## Override properties of top-level objects
   calc_old_prop = false;
@@ -92,6 +93,19 @@
       endfor
     endfor
   endif
+  
+  ## Translate field names for Matlab .fig files
+  if is_matlab_fig_file
+    for i_hg = 1:numel (hg)
+      fn = fieldnames (hg(i_hg).properties);
+      is_appdata = ismember (tolower (fn), "applicationdata");
+      if any (is_appdata)
+        ## from "applicationdata" to "__appdata__"
+        hg(i_hg).properties.__appdata__ = hg(i_hg).properties.(fn{is_appdata});
+        hg(i_hg).properties = rmfield (hg(i_hg).properties, fn{is_appdata});
+      endif
+    endfor
+  endif
 
   ## Build the graphics handle object
   h = zeros (1, numel (hg));