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 |
3361
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} str2mat (@var{s_1}, @dots{}, @var{s_n}) |
|
22 ## Return a matrix containing the strings @var{s_1}, @dots{}, @var{s_n} as |
|
23 ## its rows. Each string is padded with blanks in order to form a valid |
|
24 ## matrix. |
3426
|
25 ## |
3361
|
26 ## @strong{Note:} |
|
27 ## This function is modelled after @sc{Matlab}. In Octave, you can create |
|
28 ## a matrix of strings by @code{[@var{s_1}; @dots{}; @var{s_n}]} even if |
|
29 ## the strings are not all the same length. |
|
30 ## @end deftypefn |
2311
|
31 |
2355
|
32 ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> |
|
33 ## Adapted-By: jwe |
2314
|
34 |
3979
|
35 function retval = str2mat (varargin) |
2325
|
36 |
2273
|
37 if (nargin == 0) |
|
38 usage ("str2mat (s1, ...)"); |
|
39 endif |
|
40 |
|
41 nc = 0; |
3168
|
42 nr = 0; |
2273
|
43 |
3168
|
44 nr = zeros (nargin, 1); |
|
45 nc = zeros (nargin, 1); |
2273
|
46 for k = 1 : nargin |
3979
|
47 s = varargin{k}; |
3705
|
48 if (! isstr (s)) |
|
49 s = setstr (s); |
2273
|
50 endif |
3705
|
51 [nr(k), nc(k)] = size (s); |
2273
|
52 endfor |
|
53 |
3174
|
54 tmp = find (nr == 0); |
|
55 |
|
56 if (! isempty (tmp)) |
|
57 nr(tmp) = 1; |
|
58 endif |
|
59 |
3168
|
60 retval_nr = sum (nr); |
|
61 retval_nc = max (nc); |
|
62 |
|
63 retval = setstr (ones (retval_nr, retval_nc) * toascii (" ")); |
2273
|
64 |
3168
|
65 row_offset = 0; |
2273
|
66 for k = 1 : nargin |
3979
|
67 s = varargin{k}; |
3705
|
68 if (! isstr (s)) |
|
69 s = setstr (s); |
|
70 endif |
3168
|
71 if (nc(k) > 0) |
|
72 retval ((row_offset + 1) : (row_offset + nr(k)), 1:nc(k)) = s; |
2273
|
73 endif |
3168
|
74 row_offset = row_offset + nr(k); |
2273
|
75 endfor |
2325
|
76 |
2273
|
77 endfunction |