# HG changeset patch # User Juan Pablo Carbajal # Date 1434552729 -7200 # Node ID f357e076776f7f09a56acf1ecc4d5ba7ec763a20 # Parent 01895a6acdded4a1704c9437b228c78fede3c867 num2str.m: Fixed two Matlab compatibility issues (bug #45174, bug #44864). * num2str.m: Don't use repmat to modify user-supplied conversion format if it contains more than one conversion specifier or if the string (%s) or character (%c) conversions are present. diff -r 01895a6acdde -r f357e076776f scripts/general/num2str.m --- a/scripts/general/num2str.m Mon Jun 15 17:52:27 2015 -0400 +++ b/scripts/general/num2str.m Wed Jun 17 16:52:09 2015 +0200 @@ -116,10 +116,14 @@ endif endif fmt = do_string_escapes (fmt); # required now that '\n' is interpreted. - fmt = [deblank(repmat (fmt, 1, columns (x))), "\n"]; nd = ndims (x); - tmp = sprintf (fmt, permute (x, [2, 1, 3:nd])); - retval = strtrim (char (ostrsplit (tmp(1:end-1), "\n"))); + nc = columns (x); + x = permute (x, [2, 1, 3:nd]); + if (! (sum (fmt == "%") > 1 || any (strcmp (fmt, {"%s", "%c"})))) + fmt = [deblank(repmat (fmt, 1, nc)), "\n"]; + endif + tmp = sprintf (fmt, x); + retval = strtrim (char (ostrsplit (tmp, "\n", true))); else # Complex matrix input if (nargin == 2) if (ischar (arg)) @@ -208,6 +212,9 @@ ## Test for bug #44864, extra rows generated from newlines in format %!assert (rows (num2str (magic (3), '%3d %3d %3d\n')), 3) +## Test for bug #45174 +%!assert (num2str ([65 66 67], '%s'), "ABC") + %!error num2str () %!error num2str (1, 2, 3) %!error num2str ({1})