octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Matlab compatability for strtrim


From: Rik
Subject: Re: Matlab compatability for strtrim
Date: Sat, 23 Jul 2011 08:12:21 -0700

On 07/22/2011 05:25 PM, Michael D Godfrey wrote:
> On 07/22/2011 05:05 PM, Rik wrote:
>> 7/22/11
>>
>> While trying to make strtrim () perform better I ran into some questions
>> about compatibility with Matlab.  Could someone with Matlab access try the
>> following two tests?
>>
>> find (isspace (char(0):char(255)))
>>
>> double (strtrim (char ([0 0 65:67 32 10])))
>>
>> Thanks,
>> Rik
>                                                 Copyright 1984-2009 The
> MathWorks, Inc.
>                                                 Version 7.9.0.529 (R2009b)
> 64-bit (glnxa64)
>                                                               August 12, 2009
> 
>  
>   To get started, type one of these: helpwin, helpdesk, or demo.
>   For product information, visit www.mathworks.com.
>  
>>> find (isspace (char(0):char(255)))
> 
> ans =
> 
>     10    11    12    13    14    33   134   161
> 
>>> double (strtrim (char ([0 0 65:67 32 10])))
> 
> ans =
> 
>      0     0    65    66    67
> 
>>>
> 
7/23/11

All,

This does introduce some issues.  How compatible with Matlab do we want to
be regarding strtrim?  First, the Octave version is stripping out nulls (0)
which it shouldn't do.  But the real issue is the extra ASCII characters
133 and 160 which Matlab believes are space characters.  According to the
Matlab documentation, strtrim should remove all characters for which
isspace is true.  However, on my Linux system isspace does not include
characters 133 and 160.  Is that good enough, since we are following the
documentation exactly.  Or should we attempt to follow what Matlab does in
practice?  I, personally, would rather not deviate from the underlying C
library routines since I'm sure they're optimized.

Michael,

Can you try the following to see how it handles char arrays?

s = strtrim ([" abc   "; "      d "]

size (s)

Regards,
Rik


reply via email to

[Prev in Thread] Current Thread [Next in Thread]