1######################################################################## 2## 3## Copyright (C) 1996-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {} blanks (@var{n}) 28## Return a string of @var{n} blanks. 29## 30## For example: 31## 32## @example 33## @group 34## blanks (10); 35## whos ans 36## @result{} 37## Attr Name Size Bytes Class 38## ==== ==== ==== ===== ===== 39## ans 1x10 10 char 40## @end group 41## @end example 42## @seealso{repmat} 43## @end deftypefn 44 45function s = blanks (n) 46 47 if (nargin != 1) 48 print_usage (); 49 elseif (! (isscalar (n) && n == fix (n) && n >= 0)) 50 error ("blanks: N must be a non-negative integer"); 51 endif 52 53 ## If 1:n is empty, the following expression will create an empty 54 ## character string. Otherwise, it will create a row vector. 55 s(1:n) = " "; 56 57endfunction 58 59 60## There really isn't that much to test here 61%!assert (blanks (0), "") 62%!assert (blanks (5), " ") 63%!assert (blanks (10), " ") 64 65## Test input validation 66%!error blanks () 67%!error blanks (1, 2) 68%!error blanks (ones (2)) 69%!error blanks (2.1) 70%!error blanks (-2) 71