STRCAT is not compatible

Ben Abbott bpabbott at mac.com
Wed Feb 20 21:59:23 CST 2008


On Feb 20, 2008, at 3:02 PM, John W. Eaton wrote:

> On 20-Feb-2008, Tribo Laboy wrote:
>
> | While porting some ML code to octave I found that STRCAT in Octave
> | 3.0.0 is not compatible to ML 2006a.
> | Octave behaviour is as documented in the manual, so strictly  
> speaking
> | this is not a bug.
> |
> | In summary, Matlab allows one of the arguments to be a cell array of
> | strings, or both to be cell arrays if they have equal size.
> |
> | These two examples illustrate Matlab behaviour:
> |
> | >>  ca = {'a','b','c'};
> | >>  s = 'xyz';
> | >> strcat(s,ca)
> |
> | ans =
> |
> |     'xyza'    'xyzb'    'xyzc'
> |
> | >> strcat({'Red','Yellow'},{'Green','Blue'})
> |
> | ans =
> |
> |     'RedGreen'    'YellowBlue'
> |
> |
> | In Octave 3.0.0 these examples result in errors:
> |
> | >> ca = {'a','b','c'};
> | >> s = 'xyz';
> | >> strcat(s,ca)
> | error: strcat: all arguments must be strings
> | error: evaluating if command near line 38, column 3
> | error: called from `strcat' in file `D:\PORT\PortApps\MATH\qtoctave 
> \Octave\shar
> | e\octave\3.0.0\m\strings\strcat.m'
> |
> | >> strcat({'Red','Yellow'},{'Green','Blue'})
> | error: strcat: all arguments must be strings
> | error: evaluating if command near line 38, column 3
> | error: called from `strcat' in file `D:\PORT\PortApps\MATH\qtoctave 
> \Octave\shar
> | e\octave\3.0.0\m\strings\strcat.m'
>
> OK, I checked in the following changes to at least detect the cellstr
> args.  To make strcat behavior compatible, somone will need to
> implement the strcat_cell subfunction in scripts/strings/strcat.m.
>
> jwe

<snip>

> +%!xtest
> +%! assert(all (strcmp (strcat ("a", {"bc", "de"}, "f"), {"abcf",  
> "adef"})))
> +

I took a quick look. There are additional compatibility problems.

%!xtest
%! assert(all (strcmp (strcat (["a"; "b"], "c"), ["ac"; "bc"])))

%!xtest
%! assert(all (strcmp (strcat ({"a", "bb"}, "ccc"), {"accc", "bbccc"})))

%!xtest
%! assert(all (strcmp (strcat ("a", {"bb", "ccc"}), {"abb", "accc"})))

I'll think this over. If no one else comes up with a solution, I'll  
take a shot at it.

Ben


More information about the Bug-octave mailing list