changeset 30981:1ce1c4552d5b stable

datenum.m: Correctly handle arrays with leading singleton dimensions (bug #62407). * scripts/time/datenum.m: Reshape input internally if it is not a column vector.
author Nir Krakauer <nkrakauer@ccny.cuny.edu>
date Thu, 05 May 2022 20:47:09 +0200
parents 302faf5bc425
children 95cb7ebba1a9 8ee6422d1292
files scripts/time/datenum.m
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/time/datenum.m	Thu May 05 19:23:06 2022 +0200
+++ b/scripts/time/datenum.m	Thu May 05 20:47:09 2022 +0200
@@ -136,8 +136,7 @@
       endif
       ## Preserve shape if necessary, and work with column vectors
       ## for the remainder of the function.
-      do_reshape = (columns (year) > 1 || columns (month) > 1
-                    || columns (day) > 1);
+      do_reshape = ! iscolumn (day);
       if (do_reshape)
         sz_reshape = size (day);
         year = year(:);
@@ -217,6 +216,8 @@
 %! n = n';
 %! assert (datenum (t(1,:), t(2,:), t(3,:), t(4,:), t(5,:), t(6,:)), n, 2*eps);
 
+%!assert (size (datenum (2000, 1, ones(1, 1, 3))), [1 1 3])
+
 ## Test fractional years including leap years
 %!assert (fix (datenum ([2001.999 1 1; 2001.999 2 1])), [731216; 731247])
 %!assert (fix (datenum ([2004.999 1 1; 2004.999 2 1])), [732312; 732343])