7017
|
1 ## Copyright (C) 1996, 1997, 1999, 2002, 2003, 2005, 2006, 2007 |
|
2 ## Kurt Hornik |
2325
|
3 ## |
2313
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
2268
|
19 |
3361
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} blanks (@var{n}) |
|
22 ## Return a string of @var{n} blanks. |
6138
|
23 ## @seealso{repmat} |
3361
|
24 ## @end deftypefn |
2311
|
25 |
5428
|
26 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
2355
|
27 ## Adapted-By: jwe |
2314
|
28 |
2268
|
29 function s = blanks (n) |
2325
|
30 |
2268
|
31 if (nargin != 1) |
6046
|
32 print_usage (); |
6138
|
33 elseif (! (isscalar (n) && n == round (n))) |
3081
|
34 error ("blanks: n must be a non-negative integer"); |
2268
|
35 endif |
2325
|
36 |
6387
|
37 ## If 1:n is empty, the following expression will create an empty |
|
38 ## character string. Otherwise, it will create a row vector. |
|
39 s(1:n) = " "; |
6138
|
40 |
2268
|
41 endfunction |
6138
|
42 |
|
43 ## There really isn't that much to test here |
|
44 %!assert(blanks (0), "") |
|
45 %!assert(blanks (5), " ") |
|
46 %!assert(blanks (10), " ") |
7411
|
47 |
|
48 %!assert(strcmp (blanks (3), " ")); |
|
49 |
|
50 %!error blanks (); |
|
51 |
|
52 %!error blanks (1, 2); |
|
53 |