bugGNU Octave - Bugs: bug #33334, Concatenation cell strings and...

 
 

bug #33334: Concatenation cell strings and strings

Submitter:  David Bateman <dbateman>
Submitted:  Tue 17 May 2011 08:30:04 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  David Bateman Open/Closed:  * Closed
Release:  * 3.4.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 09 May 2012 06:43:27 AM UTC, comment #9: 

This one seems to be fixed. Can this be closed now?

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Wed 18 May 2011 09:41:49 PM UTC, comment #8: 

Matlab has its mysterious ways.  Here is the latest:


>> version


ans =

7.9.0.529 (R2009b)

>> ['s1', {[1,1]}]


ans =

    's1'    [1x2 double]

>> [{[1,1]}, 's1']


ans =

    [1x2 double]    's1'

>>

Michael Godfrey <godfrey>
Group Member
Wed 18 May 2011 09:16:07 PM UTC, comment #7: 

Well if you want to know the results weren't what I was expecting. Why should all three arguments be promoted to cell strings in the first example, but in the third case only after the two strings are concatenated.. This seems like another case of an adhoc matlab implementation.

In fact I now have another case that might be problematic. What does matlab give for

['s1', {[1,1]}]
[{[1,1]}, 's1']

That is does the promotion of the strings only happen is the cell array contains strings, or does the promotion always happen?

D.

David Bateman <dbateman>
Group Member
Wed 18 May 2011 07:00:35 AM UTC, comment #6: 

I will not speculate about what you expected this time:

>> version


ans =

7.9.0.529 (R2009b)

>> ['s1', 's2', {'s3'}]


ans =

    's1'    's2'    's3'

>> ['s1'; 's2'; {'s3'}]


ans =

    's1'
    's2'
    's3'

>> ['s1', 's2'; {'s3'}]


ans =

    's1s2'
    's3'

>>


Michael Godfrey <godfrey>
Group Member
Wed 18 May 2011 06:52:38 AM UTC, comment #5: 

Ok its a little harder than I thought because we have to promote the strings to cell strings before checking the dimensions in the concatenation. However this raises another question of how matlab handles these cases

['s1', 's2', {'s3'}]
['s1'; 's2'; {'s3'}]
['s1', 's2'; {'s3'}]

D.

David Bateman <dbateman>
Group Member
Wed 18 May 2011 03:42:42 AM UTC, comment #4: 

Okay, it does promote to cell string.  I'm used to the Octave output which displays '{'/'}' around the answer when the type is of class cell.

Rik <rik5>
Group administrator
Wed 18 May 2011 03:24:39 AM UTC, comment #3: 

Apparently not: (same Matlab)

>> s = {'s1'};            
>> s = [s; 's2'; 's3']    


s =

    's1'
    's2'
    's3'

>> sx = ['sx']


sx =

sx

>> whos

  Name      Size            Bytes  Class    Attributes

  s         3x1               348  cell              
  sx        1x2                 4  char              

>> sy = s(2)


sy =

    's2'

>> whos

  Name      Size            Bytes  Class    Attributes

  s         3x1               348  cell              
  sx        1x2                 4  char              
  sy        1x1               116  cell              

>>

=================================
This seems a bit odd.  Does it help?

Michael Godfrey <godfrey>
Group Member
Tue 17 May 2011 11:30:27 PM UTC, comment #2: 

Doesn't the test indicate the reverse?  That the cellstr was demoted to an ordinary string and returned in a char array along with the other two strings.

Rik <rik5>
Group administrator
Tue 17 May 2011 09:30:38 PM UTC, comment #1: 

As you guessed, Matlab says:

>> version


ans =

7.9.0.529 (R2009b)

>> s = {'s1'};
>> s = [s; 's2'; 's3']


s =

    's1'
    's2'
    's3'

>>


Michael Godfrey <godfrey>
Group Member
Tue 17 May 2011 08:30:04 PM UTC, original submission:  

While porting some code I ran across the following construct


s = {'s1'};
s = [s; 's2'; 's3']


Octave fails for the above. I no longer have access to matlab and can't easily check that matlab in fact supports the above. But the use of this code in the package I'm porting seems to imply that matlab promotes the strings to cell strings. So if someone could check the above and send the result it would be great.

The fix is relatively trivial with the addition of two concatenation methods in op-cell.cc

D.

David Bateman <dbateman>
Group Member

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

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 godfrey (Posted a comment)
  • -email is unavailable- added by dbateman (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-06-22 rik5 Item GroupIncorrect Result Matlab Compatibility
        StatusNeed Info Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code