changeset 31871:9546e993e9ee

[xyz]ticklabels.m: Allow empty char array input for Matlab compatibility (bug #63859). * xticklabels.m, yticklabels.m, zticklabels.m: Detect empty input ({}, [], or '') and map to empty cell array {}. Use 'lower' rather than 'tolower' and don't transform input argument so that any error messages will report exactly what was typed.
author Rik <rik@octave.org>
date Wed, 01 Mar 2023 22:16:34 -0800
parents 6a2638cbea96
children cfeda68b01ad
files scripts/plot/appearance/xticklabels.m scripts/plot/appearance/yticklabels.m scripts/plot/appearance/zticklabels.m
diffstat 3 files changed, 28 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/xticklabels.m	Wed Mar 01 19:46:20 2023 -0800
+++ b/scripts/plot/appearance/xticklabels.m	Wed Mar 01 22:16:34 2023 -0800
@@ -88,6 +88,14 @@
     hax = gca ();
   endif
 
+  if (! (iscell (arg) || isnumeric (arg) || ischar (arg)))
+    print_usage ();
+  endif
+
+  if (isempty (arg))
+    arg = {};  # Either '' or [] are converted empty cell array
+  endif
+
   if (iscell (arg) || isnumeric (arg))
     if (nargout > 0)
       error ("xticklabels: too many output arguments requested");
@@ -99,7 +107,6 @@
       ## This implementation allows for a numeric array, which is handled in
       ## the same order as Matlab handles a cell array
       arg = num2cell (arg(:));
-
     endif
 
     ## Convert any numeric elements to characters, make it a 1-D cell array.
@@ -114,8 +121,7 @@
               "xtickmode", "manual");
 
   elseif (ischar (arg))
-    arg = tolower (arg);
-    switch (arg)
+    switch (lower (arg))
       case "mode"
         labels = get (hax, "xticklabelmode");
 
@@ -131,8 +137,6 @@
 
     endswitch
 
-  else
-    print_usage ();
   endif
 
 endfunction
--- a/scripts/plot/appearance/yticklabels.m	Wed Mar 01 19:46:20 2023 -0800
+++ b/scripts/plot/appearance/yticklabels.m	Wed Mar 01 22:16:34 2023 -0800
@@ -88,6 +88,14 @@
     hax = gca ();
   endif
 
+  if (! (iscell (arg) || isnumeric (arg) || ischar (arg)))
+    print_usage ();
+  endif
+
+  if (isempty (arg))
+    arg = {};  # Either '' or [] are converted empty cell array
+  endif
+
   if (iscell (arg) || isnumeric (arg))
     if (nargout > 0)
       error ("yticklabels: too many output arguments requested");
@@ -99,7 +107,6 @@
       ## This implementation allows for a numeric array, which is handled in
       ## the same order as Matlab handles a cell array
       arg = num2cell (arg(:));
-
     endif
 
     ## Convert any numeric elements to characters, make it a 1-D cell array.
@@ -113,9 +120,8 @@
               "yticklabelmode", "manual",
               "ytickmode", "manual");
 
-  elseif (ischar (arg))
-    arg = tolower (arg);
-    switch (arg)
+  else
+    switch (lower (arg))
       case "mode"
         labels = get (hax, "yticklabelmode");
 
@@ -131,8 +137,6 @@
 
     endswitch
 
-  else
-    print_usage ();
   endif
 
 endfunction
--- a/scripts/plot/appearance/zticklabels.m	Wed Mar 01 19:46:20 2023 -0800
+++ b/scripts/plot/appearance/zticklabels.m	Wed Mar 01 22:16:34 2023 -0800
@@ -88,6 +88,14 @@
     hax = gca ();
   endif
 
+  if (! (iscell (arg) || isnumeric (arg) || ischar (arg)))
+    print_usage ();
+  endif
+
+  if (isempty (arg))
+    arg = {};  # Either '' or [] are converted empty cell array
+  endif
+
   if (iscell (arg) || isnumeric (arg))
     if (nargout > 0)
       error ("zticklabels: too many output arguments requested");
@@ -99,7 +107,6 @@
       ## This implementation allows for a numeric array, which is handled in
       ## the same order as Matlab handles a cell array
       arg = num2cell (arg(:));
-
     endif
 
     ## Convert any numeric elements to characters, make it a 1-D cell array.
@@ -114,8 +121,7 @@
               "ztickmode", "manual");
 
   elseif (ischar (arg))
-    arg = tolower (arg);
-    switch (arg)
+    switch (lower (arg))
       case "mode"
         labels = get (hax, "zticklabelmode");
 
@@ -131,8 +137,6 @@
 
     endswitch
 
-  else
-    print_usage ();
   endif
 
 endfunction