2303
|
1 ### Copyright (C) 1996 Kurt Hornik |
|
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 |
|
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 |
|
20 function m = str2mat (...) |
|
21 |
2303
|
22 ## usage: m = str2mat (s1, ...) |
|
23 ## |
|
24 ## Forms the matrix M containing the strings S1, ... as its rows. |
|
25 ## Each string is padded with blanks in order to form a valid matrix. |
2273
|
26 |
2303
|
27 ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>. |
2273
|
28 |
|
29 if (nargin == 0) |
|
30 usage ("str2mat (s1, ...)"); |
|
31 endif |
|
32 |
|
33 nc = 0; |
|
34 |
|
35 va_start (); |
|
36 |
|
37 for k = 1 : nargin |
|
38 s = va_arg (); |
|
39 if (isstr (s)) |
|
40 tmp = columns (s); |
|
41 else |
|
42 error ("str2mat: all arguments must be strings"); |
|
43 endif |
|
44 |
|
45 if (tmp > nc) |
|
46 nc = tmp; |
|
47 endif |
|
48 endfor |
|
49 |
|
50 m = setstr (ones (nargin, nc) * toascii (" ")); |
|
51 |
|
52 va_start (); |
|
53 |
|
54 for k = 1 : nargin |
|
55 s = va_arg (); |
|
56 tmp = columns (s); |
|
57 if (tmp > 0) |
|
58 m (k, 1:tmp) = s; |
|
59 endif |
|
60 endfor |
|
61 |
|
62 endfunction |