octave-maintainers
[Top][All Lists]
Advanced

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

Re: Matlab weirdness


From: bpabbott
Subject: Re: Matlab weirdness
Date: Mon, 10 Jan 2011 22:08:17 +0000 (GMT)

On Jan 10, 2011, at 03:40 PM, "John W. Eaton" <address@hidden> wrote:

On 9-Jan-2011, Ben Abbott wrote:

| Has this unexpected behavior been discussed before.
|
|
| >> a = ['a', 'b', {}]
|
| a = 'a' 'b'
|
| >> whos a
| Name Size Bytes Class Attributes
| a 1x2 228 cell
|
| Apparently, Matlab does an implicit conversion to cell strings.
|
| I assume we don't want to copy this, but I thought I'd ask.

I don't recall discussing this, but that doesn't mean much these
days...

I would not want to insert a special case just for this, and from this
one example, I have no idea what the general rule should be.

Is it documente somewhere?

I guess the implementation can't be

horzcat (horzcat ('a', 'b'), {})

because then 'a' and 'b' would not appear as separate elements.

Are there constraints on the order? What about

[{}, 'a', 'b']
['a', {}, 'b']
 
Both of those produce the same result, which I interpret as ...

[{}, 'a', 'b'] -> [{}, {'a'}, {'b'}]

ans =     'a'    'b'

(I assume these work).

Is this behavior limited to strings+cells? What about

['a', '1', {1,2}]
 
This produces a cell array as well.

ans =     'a'    '1'    [1]    [2]

sa = 1
[s, 'a', {1,2}]
 
??? Error using ==> horzcat
The following error occurred converting from char to struct:
Error using ==> struct
Conversion to struct from char is not possible.

['a', s, {1,2}]

??? Error using ==> horzcat
The following error occurred converting from char to struct:
Error using ==> struct
Conversion to struct from char is not possible. 

['a', {1,2}, s]
 
ans =     'a'    [1]    [2]    [1x1 struct]
 
>> whos ans
  Name      Size            Bytes  Class    Attributes

  ans       1x4               650  cell  

When I first began using cells this sort of implicit change confused me. It wasn't until using Octave, with it consistent treatment of such things, that I came to understand how cells worked.

The syntax slips my mind at the moment, but aren't there a few compatible features that are only turned on provisionally? Might this be one of them?

Ben


reply via email to

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