octave-maintainers
[Top][All Lists]
Advanced

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

Re: strcat and spaces?


From: Ben Abbott
Subject: Re: strcat and spaces?
Date: Wed, 26 Nov 2008 11:33:35 -0500

On Wednesday, November 26, 2008, at 11:24AM, "Soren Hauberg" <address@hidden> 
wrote:
>ons, 26 11 2008 kl. 10:54 -0500, skrev Ben Abbott:
>> That feature is a manifestation of how "cellstr" works. Specifically, all 
>> trailing spaces are trimmed.
>
>Okay, fair enough. So, the obvious follow-up question is: why does
>'cellstr' behave like that? I get that this is the compatible behavior,
>but I'm just trying to see the reasoning behind this. Is this some great
>feature that I simply fail to appreciate?
>
>Soren
>

I think it is due to the need to pad spaces/blanks at the end of character data 
in a matrix format.

octave:155>  c = ["one";"two";"three"]
c =

one  
two  
three

octave:156> whos c
Variables in the current scope:

  Attr Name        Size                     Bytes  Class
  ==== ====        ====                     =====  ===== 
       c           3x5                         15  char

Total is 15 elements using 15 bytes

octave:150> s = cellstr(c)
s =

{
  [1,1] = one
  [2,1] = two
  [3,1] = three
}

octave:151> numel(s{1})
ans =  3
octave:152> numel(s{2})
ans =  3
octave:153> numel(s{3})
ans =  5

When converted to cells the trailing spaces/blanks are "deblanked".

Then we can come full circle with

octave:154> c = char(s)
c =

one  
two  
three


Ben




reply via email to

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