[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cell append -empty element problem (3.6)
From: |
Ben Abbott |
Subject: |
Re: Cell append -empty element problem (3.6) |
Date: |
Thu, 13 Dec 2012 13:41:23 -0500 |
On Dec 13, 2012, at 8:40 AM, octaveuser001 wrote:
> In Octave 3.2.4 when we do
> aa=[];
> bb=cell(2,1);
> bb(1)=char('hello');
> aa=[aa;bb(1)];
>
> then the value for aa is
> aa =
> {
> [1,1] = hello
> }
>
> However with Octave 3.6.2 (windows/Visual studio 2010 Setup/Michael
> Goffioul) the returned value for aa is
> aa =
> {
> [1,1] = [](0x0)
> [2,1] = hello
> }
>
> I recently moved to 3.6 and the empty element is breaking lot of my code.
> Which is the expected correct output?
First using your example, Matlab produces ...
aa = [];
bb = cell (2, 1);
bb(1) = char ('hello');
Conversion to cell from char is not possible.
Modifying the syntax, and removing some of the semicolons for clarity ...
aa = [];
bb = cell (2, 1)
bb =
[]
[]
bb(1) = {'hello'}
bb =
'hello'
[]
aa = [aa; bb(1)]
aa =
'hello'
Notice that Matlab has dropped the contents of aa.
Octave's result does not drop the aa.
aa = [];
bb = cell (2, 1)
bb =
{
[1,1] = [](0x0)
[2,1] = [](0x0)
}
bb(1) = 'hello'
bb =
{
[1,1] = hello
[2,1] = [](0x0)
}
aa = [aa; bb(1)]
aa =
{
[1,1] = [](0x0)
[2,1] = hello
}
Now using a simpler example: First with Matlab ...
[{'foo'}, '', 'bar']
ans =
'foo' 'bar'
and now with Octave ...
[{'foo'}, '', 'bar']
ans =
{
[1,1] = foo
[1,2] =
[1,3] = bar
}
Matlab does not treat all strings equally. It converted 'bar" to a cell
string, but dropped the empty string. I would expect that [{'foo'}, '', 'bar']
to be equivalent to [{'foo'}, {''}, {'bar'}].
Also it also looks inconsistent to me that ...
bb = [{}, 'hello'];
... produces a cell-string, but using the equivalent syntax below, Matlab
throws an error .
bb = cell (1);
bb(1) = 'hello';
Conversion to cell from char is not possible.
I assume this was a bug at some point, but may now be supported by Matlab for
legacy reasons. This *feature* caused me some frustration in understanding how
cells worked in Matlab. For its consistency, I prefer the Octave
implementation.
Ben