From bug-octave-request at bevo dot che dot wisc dot edu Fri Jul 21 20:58:55 2000 Subject: Re: str2mat does not accept [] From: pkienzle at kienzle dot powernet dot co dot uk (Paul Kienzle) To: bug-octave at bevo dot che dot wisc dot edu Date: Fri, 21 Jul 2000 20:59:10 -0500 (CDT) Okay, matlab accepts both [] and '', and treats them as equivalent. Actually, matlab's str2mat seems to have an implicit setstr on all its arguments: >> str2mat(65,'B') ans = A B Unfortunately, this means that in either case my code example won't work: I will end up with a blank string at the head of my list of strings. The solution is a new function, strvcat, which in matlab does vertical concatenation but ignores empty matrices. I'll repost patches shortly. From: "John W. Eaton" >On 9-Jun-2000, Paul Kienzle wrote: > >| To: bug-octave at bevo dot che dot wisc dot edu >| Cc: pkienzle >| Subject: str2mat does not accept [] >| >| Bug report for Octave 2.0.13 configured for i386-pc-linux-gnu >| >| Description: >| ----------- >| >| I'm trying to build a matrix of strings piecemeal using something like: >| x=[]; >| while !feof(file) >| str = fscanf(file,"%s"); >| str2mat(x,str); >| endwhile >| but str2mat does not accept [] as an empty string matrix. > >I'm not sure that I would call this a bug, since `[]' is an empty >matrix, not a string. > >If you initialize x to be the empty string (x = "" instead of x = []), >then I think it should work. > >jwe > >| I don't know what matlab behaviour is in this instance. >| >| Repeat-By: >| --------- >| >| >| Fix: >| --- >| >| diff -c str2mat.m-2.1.28 str2mat >| *** str2mat.m-2.1.28 Thu Jun 8 23:18:13 2000 >| --- str2mat.m Thu Jun 8 23:26:52 2000 >| *************** >| *** 49,64 **** >| s = va_arg (); >| if (isstr (s)) >| [nr(k), nc(k)] = size (s); >| ! else >| error ("str2mat: all arguments must be strings"); >| endif >| endfor >| - >| - tmp = find (nr == 0); >| - >| - if (! isempty (tmp)) >| - nr(tmp) = 1; >| - endif >| >| retval_nr = sum (nr); >| retval_nc = max (nc); >| --- 49,61 ---- >| s = va_arg (); >| if (isstr (s)) >| [nr(k), nc(k)] = size (s); >| ! if (nr(k) == 0) >| ! nr(k) = 1; >| ! endif >| ! elseif (!isempty (s)) >| error ("str2mat: all arguments must be strings"); >| endif >| endfor >| >| retval_nr = sum (nr); >| retval_nc = max (nc); > > ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------