changeset 16306:4a3b6a80db2e

strread.m: fix division by zero when called with no output args; test added
author Philip Nienhuis <prnienhuis@users.sf.net>
date Thu, 14 Mar 2013 23:49:34 +0100
parents 23636765e00a
children f299079ed03a
files scripts/io/strread.m
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/io/strread.m	Thu Mar 14 23:38:22 2013 +0100
+++ b/scripts/io/strread.m	Thu Mar 14 23:49:34 2013 +0100
@@ -291,8 +291,8 @@
   ## First parse of FORMAT
   if (strcmpi (strtrim (format), "%f"))
     ## Default format specified.  Expand it (to desired nargout)
-    fmt_words = cell (nargout, 1);
-    fmt_words (1:nargout) = format;
+    fmt_words = cell (max (nargout, 1), 1);
+    fmt_words (1:max (nargout, 1)) = format;
   else
     ## Determine the number of words per line as a first guess.  Forms
     ## like %f<literal>) (w/o delimiter in between) are fixed further on
@@ -965,6 +965,10 @@
 %! assert (a, [1; 2], 1e-15);
 %! assert (b, [1; 3], 1e-15);
 
+%% Test for no output arg (interactive use)
+%!test
+%! assert (strread (",2,,4\n5,,7,", "", "delimiter", ","), [NaN; 2; NaN; 4; 5; NaN; 7]);
+
 %% Unsupported format specifiers
 %!test
 %!error <format specifiers are not supported> strread ("a", "%c")