2313
|
1 ## Copyright (C) 1996 Kurt Hornik |
2325
|
2 ## |
2313
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License 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 |
|
18 ## 02111-1307, USA. |
2273
|
19 |
2311
|
20 ## usage: m = str2mat (s1, ...) |
|
21 ## |
|
22 ## Forms the matrix M containing the strings S1, ... as its rows. |
|
23 ## Each string is padded with blanks in order to form a valid matrix. |
|
24 |
2314
|
25 ## Author: jwe |
|
26 |
2273
|
27 function m = str2mat (...) |
2325
|
28 |
2303
|
29 ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>. |
2273
|
30 |
|
31 if (nargin == 0) |
|
32 usage ("str2mat (s1, ...)"); |
|
33 endif |
|
34 |
|
35 nc = 0; |
|
36 |
|
37 va_start (); |
|
38 |
|
39 for k = 1 : nargin |
|
40 s = va_arg (); |
|
41 if (isstr (s)) |
|
42 tmp = columns (s); |
|
43 else |
|
44 error ("str2mat: all arguments must be strings"); |
|
45 endif |
|
46 |
|
47 if (tmp > nc) |
|
48 nc = tmp; |
|
49 endif |
|
50 endfor |
|
51 |
|
52 m = setstr (ones (nargin, nc) * toascii (" ")); |
|
53 |
|
54 va_start (); |
|
55 |
|
56 for k = 1 : nargin |
|
57 s = va_arg (); |
|
58 tmp = columns (s); |
|
59 if (tmp > 0) |
|
60 m (k, 1:tmp) = s; |
|
61 endif |
|
62 endfor |
2325
|
63 |
2273
|
64 endfunction |