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 |
3168
|
28 function retval = str2mat (...) |
2325
|
29 |
2273
|
30 if (nargin == 0) |
|
31 usage ("str2mat (s1, ...)"); |
|
32 endif |
|
33 |
|
34 nc = 0; |
3168
|
35 nr = 0; |
2273
|
36 |
|
37 va_start (); |
|
38 |
3168
|
39 nr = zeros (nargin, 1); |
|
40 nc = zeros (nargin, 1); |
2273
|
41 for k = 1 : nargin |
|
42 s = va_arg (); |
|
43 if (isstr (s)) |
3168
|
44 [nr(k), nc(k)] = size (s); |
2273
|
45 else |
|
46 error ("str2mat: all arguments must be strings"); |
|
47 endif |
|
48 endfor |
|
49 |
3168
|
50 nr(find (nr == 0)) = 1; |
|
51 retval_nr = sum (nr); |
|
52 retval_nc = max (nc); |
|
53 |
|
54 retval = setstr (ones (retval_nr, retval_nc) * toascii (" ")); |
2273
|
55 |
|
56 va_start (); |
|
57 |
3168
|
58 row_offset = 0; |
2273
|
59 for k = 1 : nargin |
|
60 s = va_arg (); |
3168
|
61 if (nc(k) > 0) |
|
62 retval ((row_offset + 1) : (row_offset + nr(k)), 1:nc(k)) = s; |
2273
|
63 endif |
3168
|
64 row_offset = row_offset + nr(k); |
2273
|
65 endfor |
2325
|
66 |
2273
|
67 endfunction |