bugGNU Octave - Bugs: bug #34123, strtrim no longer trims multilevel...

 
 

bug #34123: strtrim no longer trims multilevel cell arrays in some cases

Submitter:  Ben Barrowes <barrowes>
Submitted:  Wed 24 Aug 2011 06:25:03 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  bpabbott
Originator Name:  barrowes Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 19 Sep 2011 09:37:06 PM UTC, comment #9: 

Matlab's online docs can be read to imply that deblank behaves recursively.

"c = deblank(c) when c is a cell array of strings, applies deblank to each element of c."

http://www.mathworks.com/help/techdoc/ref/deblank.html

I don't see than implication on the other cellstr functions I looked at, so I think your conclusion is the correct thing to do.

Ben Abbott <bpabbott>
Group Member
Mon 19 Sep 2011 04:31:27 PM UTC, comment #8: 

Hmm.  Are we chasing Matlab undocumented behavior? 

The documentation doesn't make it clear whether deblank and strtrim should work on nested cellstrings or just objects for which iscellstr() returns true.  I wonder if it varies by function whether the original programmer thought to code for this case.  This would explain why strtrim works in this case and strrep doesn't.

In any case, I will code the same fix used here for deblank and then we can call it quits on Matlab compatibility for now.

Rik <rik5>
Group administrator
Mon 19 Sep 2011 02:00:26 PM UTC, comment #7: 

I check ML's iscellstr() function. It returns a false for multi-level cells of strings.


>> iscellstr (x)

ans =

     0


strrep() also fails in ML


>> x = {'123X', {'X567'}};
>> strrep (x, 'X', '4')
Error using strrep
Cell elements must be character arrays.


Ben Abbott <bpabbott>
Group Member
Mon 19 Sep 2011 12:36:56 PM UTC, comment #6: 

Rik, nice inference. Perhaps ML consistently treats cells of cells of strings as cellstings?


>> x = deblank ({'123   ', {'456  '}})

x =

    '123'    {1x1 cell}

>> length (x{2}{1})

ans =

     3


Ben Abbott <bpabbott>
Group Member
Mon 19 Sep 2011 05:08:48 AM UTC, comment #5: 

Sigh.  Yes, I was working on a private version of strtrim which accidentally got checked in.  I've checked in another changeset to rename the function.

Rik <rik5>
Group administrator
Mon 19 Sep 2011 03:38:29 AM UTC, comment #4: 

Uhm, strtrim2? Is this accidental debug code that got committed?

http://hg.savannah.gnu.org/hgweb/octave/rev/a1049e4480f8#l1.8

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Mon 19 Sep 2011 03:23:16 AM UTC, comment #3: 

Fixed in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/a1049e4480f8) along the lines suggested by Ben.

Is there a similar issue in deblank()?

What does Matlab do for the following input


x = deblank ({"123   ", {"456  "}})
length (x{2}{1})


Rik <rik5>
Group administrator
Sat 17 Sep 2011 01:41:10 AM UTC, comment #2: 

cc'n Rik

Ben Abbott <bpabbott>
Group Member
Sat 17 Sep 2011 01:35:42 AM UTC, comment #1: 

I tested the example with Matlab


>> aa = {' 123 ',{' fg'}}

aa =

    ' 123 '    {1x1 cell}

>> b = strtrim (aa)

b =

    '123'    {1x1 cell}

>> b{2}

ans =

    'fg'


I've attached a changeset. It looks a bit inelegant to me.

Is there a better way?

(file #23982)

Ben Abbott <bpabbott>
Group Member
Wed 24 Aug 2011 06:25:03 PM UTC, original submission:  

The following just stopped working with the latest dev build. Nested cell arrays no longer get strtrim'ed properly:



debug> aa={' 123  ',{' fg'}}
aa =
{
  [1,1] =  123 
  [1,2] =
  {
    [1,1] =  fg
  }
}
debug> strtrim(aa)
error: strtrim: S argument must be a string or cellstring
error: called from:
error:   /usr/local/share/octave/3.5.0+/m/strings/strtrim.m at line -1, column -1
debug>




Ben Barrowes <barrowes>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #23982:  changeset.patch added by bpabbott (1KiB - application/octet-stream - first changeset)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (Rik, can you comment on this bug report?)
  • -email is unavailable- added by bpabbott (Updated the item)
  • -email is unavailable- added by barrowes (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-09-19 rik5 Open/ClosedOpen Closed
    2011-09-19 rik5 StatusNone Fixed
    2011-09-17 bpabbott Carbon-Copy- Added -email is unavailable-
    2011-09-17 bpabbott Attached File- Added changeset.patch, #23982
        Assigned toNone bpabbott

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code