home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / strings / str2mat.m < prev    next >
Text File  |  1999-04-29  |  2KB  |  73 lines

  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.
  19.  
  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.  
  25. ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
  26. ## Adapted-By: jwe
  27.  
  28. function retval = str2mat (...)
  29.  
  30.   if (nargin == 0)
  31.     usage ("str2mat (s1, ...)");
  32.   endif
  33.  
  34.   nc = 0;
  35.   nr = 0;
  36.  
  37.   va_start ();
  38.  
  39.   nr = zeros (nargin, 1);
  40.   nc = zeros (nargin, 1);
  41.   for k = 1 : nargin
  42.     s = va_arg ();
  43.     if (isstr (s))
  44.       [nr(k), nc(k)] = size (s);
  45.     else
  46.       error ("str2mat: all arguments must be strings");
  47.     endif
  48.   endfor
  49.  
  50.   tmp = find (nr == 0);
  51.  
  52.   if (! isempty (tmp))
  53.     nr(tmp) = 1;
  54.   endif
  55.  
  56.   retval_nr = sum (nr);
  57.   retval_nc = max (nc);
  58.  
  59.   retval = setstr (ones (retval_nr, retval_nc) * toascii (" "));
  60.  
  61.   va_start ();
  62.  
  63.   row_offset = 0;
  64.   for k = 1 : nargin
  65.     s = va_arg ();
  66.     if (nc(k) > 0)
  67.       retval ((row_offset + 1) : (row_offset + nr(k)), 1:nc(k)) = s;
  68.     endif
  69.     row_offset = row_offset + nr(k);
  70.   endfor
  71.  
  72. endfunction
  73.