Mercurial > hg > octave-terminal
changeset 14430:df5488e46dca
fix bug in input validation for textread
* textread.m: fix a bug in input validation when
headerlines is the only option passed
author | Carlo de Falco <kingcrimson@tiscali.it> |
---|---|
date | Sun, 04 Mar 2012 22:52:41 +0100 |
parents | eff4a5933e28 |
children | f22a9555aa69 |
files | scripts/io/textread.m |
diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/textread.m +++ b/scripts/io/textread.m @@ -71,8 +71,8 @@ fskipl (fid, varargin{headerlines + 1}); varargin(headerlines:headerlines+1) = []; endif - - if (nargin > 2 && isnumeric (varargin{1})) + + if (! isempty (varargin) && isnumeric (varargin{1})) nlines = varargin{1}; else nlines = Inf; @@ -140,6 +140,14 @@ %! assert (b, d(4:5, 2), 1e-2); %! assert (c, d(4:5, 3), 1e-2); +%!test +%! f = tmpnam (); +%! d = rand (7, 2); +%! dlmwrite (f, d, "precision", "%5.2f"); +%! [a, b] = textread (f, "%f, %f", "headerlines", 1); +%! unlink (f); +%! assert (a, d(2:7, 1), 1e-2); + %% Test input validation %!error textread () %!error textread (1)