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 |
2355
|
25 ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> |
|
26 ## Adapted-By: jwe |
2314
|
27 |
2273
|
28 function m = str2mat (...) |
2325
|
29 |
2273
|
30 if (nargin == 0) |
|
31 usage ("str2mat (s1, ...)"); |
|
32 endif |
|
33 |
|
34 nc = 0; |
|
35 |
|
36 va_start (); |
|
37 |
|
38 for k = 1 : nargin |
|
39 s = va_arg (); |
|
40 if (isstr (s)) |
|
41 tmp = columns (s); |
|
42 else |
|
43 error ("str2mat: all arguments must be strings"); |
|
44 endif |
|
45 |
|
46 if (tmp > nc) |
|
47 nc = tmp; |
|
48 endif |
|
49 endfor |
|
50 |
|
51 m = setstr (ones (nargin, nc) * toascii (" ")); |
|
52 |
|
53 va_start (); |
|
54 |
|
55 for k = 1 : nargin |
|
56 s = va_arg (); |
|
57 tmp = columns (s); |
|
58 if (tmp > 0) |
|
59 m (k, 1:tmp) = s; |
|
60 endif |
|
61 endfor |
2325
|
62 |
2273
|
63 endfunction |