2273
|
1 # Copyright (C) 1996 John W. Eaton |
|
2 # |
|
3 # This file is part of Octave. |
|
4 # |
|
5 # Octave is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License as published by the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with Octave; see the file COPYING. If not, write to the Free |
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
18 |
|
19 function m = str2mat (...) |
|
20 |
|
21 # usage: m = str2mat (s1, ...) |
|
22 # |
|
23 # Forms the matrix M containing the strings S1, ... as its rows. |
|
24 # Each string is padded with blanks in order to form a valid matrix. |
|
25 |
|
26 # Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>. |
|
27 |
|
28 if (nargin == 0) |
|
29 usage ("str2mat (s1, ...)"); |
|
30 endif |
|
31 |
|
32 nc = 0; |
|
33 |
|
34 va_start (); |
|
35 |
|
36 for k = 1 : nargin |
|
37 s = va_arg (); |
|
38 if (isstr (s)) |
|
39 tmp = columns (s); |
|
40 else |
|
41 error ("str2mat: all arguments must be strings"); |
|
42 endif |
|
43 |
|
44 if (tmp > nc) |
|
45 nc = tmp; |
|
46 endif |
|
47 endfor |
|
48 |
|
49 m = setstr (ones (nargin, nc) * toascii (" ")); |
|
50 |
|
51 va_start (); |
|
52 |
|
53 for k = 1 : nargin |
|
54 s = va_arg (); |
|
55 tmp = columns (s); |
|
56 if (tmp > 0) |
|
57 m (k, 1:tmp) = s; |
|
58 endif |
|
59 endfor |
|
60 |
|
61 endfunction |