Matlab compatibilty [changeset] for strcat

Ben Abbott bpabbott at mac.com
Wed Sep 24 12:45:47 CDT 2008


On Sep 23, 2008, at 10:50 PM, Ben Abbott wrote:

> On Sep 23, 2008, at 9:20 PM, Erich Ritz wrote:
>
>> I tried searching to see if this issue was already posted; forgive
>> me if it is.
>>
>> Matlab allows:
>>
>> my_str = strcat([], 'a')
>>
>> and octave gives an error: error: strcat: all arguments must be
>> strings
>>
>> The rational for the above statement is:
>>
>> my_str = [];
>> for ...
>>   ...
>>   my_str = strcat(my_str, 'some text');
>> end
>>
>> The work around is to do:
>> my_str = '';
>> instead when initializing.
>>
>> Note also that octave allows
>> my_str = [my_str 'some text'];
>> in the above context, but [] behave differently than strcat().
>>
>> Erich
>
> hmmm ... another example. Running Matlab ...
>
> 	>> strcat (33, 33)
> 	ans =
> 	!!
> 	
> Even stranger, real numbers are round down (floor)
>
> 	>> strcat (33.7, 33)
> 	ans =
> 	!!
>
> I guess all positive reals work going in, but return characters in all
> cases.
>
> 	>> strcat(-19,33)
> 	Warning: Out of range or non-integer values truncated during
> conversion to character.
> 	ans =
> 	 !
>
> Even, out of range numbers give a warning, but no error.
>
> This should be rather easy to fix. If no one gets to it, I'll take a
> look later tomorrow.
>

I've created a short change set for strcat to respect the Matlab  
functionality. A pair of tests are included.

As char(-19) already gives a warning similar to Matlab, and appears to  
work in a compatible manner, this was quite simple.

	>  x = char(-19)
	warning: range error for conversion to character value

Ben

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: changeset-strcat.txt
Url: https://www-old.cae.wisc.edu/pipermail/bug-octave/attachments/20080924/07d1221f/attachment.txt 
-------------- next part --------------




More information about the Bug-octave mailing list