http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030
MATLAB Central Newsreader  Comma list with leading cell
Feed for thread: Comma list with leading cell
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Sat, 23 May 2009 11:45:02 +0000
Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651846
Bruno Luong
This syntax works it is beyond my expectation! Is it documented somewhere?<br>
<br>
>> [{} 1 2 3]<br>
<br>
ans = <br>
<br>
[1] [2] [3]<br>
<br>
% To me the correct syntax is<br>
<br>
>> [{} {1 2 3}]<br>
<br>
Bruno

Sat, 23 May 2009 12:45:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651849
us
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8nju$kvn$1@fred.mathworks.com>...<br>
> This syntax works it is beyond my expectation! Is it documented somewhere?<br>
> <br>
> >> [{} 1 2 3]<br>
> <br>
> ans = <br>
> <br>
> [1] [2] [3]<br>
> <br>
> % To me the correct syntax is<br>
> <br>
> >> [{} {1 2 3}]<br>
> <br>
> Bruno<br>
<br>
it is a weel known fact of ML life<br>
<br>
...<br>
When MATLAB sees a subscripted assignment to an existing variable, MATLAB checks the class of the righthandside against the class of the lefthandside (LHS) variable. If different, it attempts to convert the righthandside (RHS) variable to the type of the LHS class.<br>
...<br>
<br>
['a' nan]<br>
[uint8(1) pi]<br>
[pi uint8(1)]<br>
<br>
here some of the tech docs this is referred to<br>
<br>
<a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
<a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
<br>
us

Sat, 23 May 2009 12:54:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651850
us
"us " <us@neurol.unizh.ch> wrote in message <gv8r4e$19v$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8nju$kvn$1@fred.mathworks.com>...<br>
> > This syntax works it is beyond my expectation! Is it documented somewhere?<br>
> > <br>
> > >> [{} 1 2 3]<br>
> > <br>
> > ans = <br>
> > <br>
> > [1] [2] [3]<br>
> > <br>
> > % To me the correct syntax is<br>
> > <br>
> > >> [{} {1 2 3}]<br>
> > <br>
> > Bruno<br>
> <br>
> it is a weel known fact of ML life<br>
> <br>
> ...<br>
> When MATLAB sees a subscripted assignment to an existing variable, MATLAB checks the class of the righthandside against the class of the lefthandside (LHS) variable. If different, it attempts to convert the righthandside (RHS) variable to the type of the LHS class.<br>
> ...<br>
> <br>
> ['a' nan]<br>
> [uint8(1) pi]<br>
> [pi uint8(1)]<br>
> <br>
> here some of the tech docs this is referred to<br>
> <br>
> <a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
> <a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
> <br>
> us<br>
<br>
btw, we've been using this sometimes to bypass NUM2CELL...<br>
it seems a bit faster...<br>
<br>
us

Sat, 23 May 2009 12:59:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651851
Bruno Luong
"us " <us@neurol.unizh.ch> wrote in message <gv8r4e$19v$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8nju$kvn$1@fred.mathworks.com>...<br>
> > This syntax works it is beyond my expectation! Is it documented somewhere?<br>
> > <br>
> > >> [{} 1 2 3]<br>
> > <br>
> > ans = <br>
> > <br>
> > [1] [2] [3]<br>
> > <br>
> > % To me the correct syntax is<br>
> > <br>
> > >> [{} {1 2 3}]<br>
> > <br>
> > Bruno<br>
> <br>
> it is a weel known fact of ML life<br>
> <br>
> ...<br>
> When MATLAB sees a subscripted assignment to an existing variable, MATLAB checks the class of the righthandside against the class of the lefthandside (LHS) variable. If different, it attempts to convert the righthandside (RHS) variable to the type of the LHS class.<br>
> ...<br>
> <br>
> ['a' nan]<br>
> [uint8(1) pi]<br>
> [pi uint8(1)]<br>
> <br>
> here some of the tech docs this is referred to<br>
> <br>
> <a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
> <a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
> <br>
<br>
Humm it is clearer but not perfect, because why this doesn't work:<br>
<br>
>> a={1}<br>
<br>
a = <br>
<br>
[1]<br>
<br>
>> class(a)<br>
<br>
ans =<br>
<br>
cell<br>
<br>
>> a(1)=2<br>
??? Conversion to cell from double is not possible.<br>
<br>
I'm still confused. It seems the example I gave above Matlab succeeds to convert somehow double to cell? Why now it can't.<br>
<br>
Bruno

Sat, 23 May 2009 13:02:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651852
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv8r4e$19v$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8nju$kvn$1@fred.mathworks.com>...<br>
> > This syntax works it is beyond my expectation! Is it documented somewhere?<br>
> > <br>
> > >> [{} 1 2 3]<br>
> > <br>
> > ans = <br>
> > <br>
> > [1] [2] [3]<br>
> > <br>
> > % To me the correct syntax is<br>
> > <br>
> > >> [{} {1 2 3}]<br>
> > <br>
> > Bruno<br>
> <br>
> it is a weel known fact of ML life<br>
> <br>
> ...<br>
> When MATLAB sees a subscripted assignment to an existing variable, MATLAB checks the class of the righthandside against the class of the lefthandside (LHS) variable. If different, it attempts to convert the righthandside (RHS) variable to the type of the LHS class.<br>
<br>
<br>
I'm not convinced that that explains it, since Bruno's example was not in fact an assignment (there was no LHS variable). Also, if it were a case of a cell on the LHS converting numeric data on the RHS, the following ought to have produced the same effect<br>
<br>
>> a={}<br>
<br>
a = <br>
<br>
{}<br>
<br>
>> a(2:4)=[1 2 3]<br>
??? Conversion to cell from double is not possible.

Sat, 23 May 2009 13:17:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651855
us
"Matt " <xys@whatever.com> wrote in message <gv8s49$2ua$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv8r4e$19v$1@fred.mathworks.com>...<br>
> > "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8nju$kvn$1@fred.mathworks.com>...<br>
> > > This syntax works it is beyond my expectation! Is it documented somewhere?<br>
> > > <br>
> > > >> [{} 1 2 3]<br>
> > > <br>
> > > ans = <br>
> > > <br>
> > > [1] [2] [3]<br>
> > > <br>
> > > % To me the correct syntax is<br>
> > > <br>
> > > >> [{} {1 2 3}]<br>
> > > <br>
> > > Bruno<br>
> > <br>
> > it is a weel known fact of ML life<br>
> > <br>
> > ...<br>
> > When MATLAB sees a subscripted assignment to an existing variable, MATLAB checks the class of the righthandside against the class of the lefthandside (LHS) variable. If different, it attempts to convert the righthandside (RHS) variable to the type of the LHS class.<br>
> <br>
> <br>
> I'm not convinced that that explains it, since Bruno's example was not in fact an assignment (there was no LHS variable)...<br>
<br>
actually, it is  hidden; the construct is just not using the typical a=b syntax...<br>
anyhow, this doc page may be more useful re combining unlike classes<br>
<br>
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
<br>
us

Sat, 23 May 2009 13:26:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651857
us
"Bruno Luong"<br>
> Humm it is clearer but not perfect, because why this doesn't work:<br>
> >> a={1}<br>
> a = <br>
> [1]<br>
> >> class(a)<br>
> ans =<br>
> cell<br>
> >> a(1)=2<br>
> ??? Conversion to cell from double is not possible.<br>
> <br>
> I'm still confused. It seems the example I gave above Matlab succeeds to convert somehow double to cell? Why now it can't...<br>
<br>
well,<br>
in your first case, ML knows nothing about the content of the container during execution and simply converts all its entries (=within container) according to some (published) rules...<br>
<br>
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
<br>
in your second case, ML knows the class of the lhs and tells you that it cannot add another class (=between containers)<br>
<br>
somehow, this all makes sense (to me)...<br>
:)<br>
urs

Sat, 23 May 2009 13:28:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651859
Bruno Luong
"us " <us@neurol.unizh.ch> wrote in message <gv8t0d$rm7$1@fred.mathworks.com>...<br>
<br>
> <br>
> <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
> <br>
<br>
But us, let us reiterate the question. Why conversion from double to cell<br>
<br>
C = {1};<br>
C(1) = 2<br>
<br>
is not allowed?<br>
<br>
Bruno

Sat, 23 May 2009 13:41:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651860
us
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8tl1$81o$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv8t0d$rm7$1@fred.mathworks.com>...<br>
> <br>
> > <br>
> > <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
> > <br>
> <br>
> But us, let us reiterate the question. Why conversion from double to cell<br>
> <br>
> C = {1};<br>
> C(1) = 2<br>
> <br>
> is not allowed?<br>
> <br>
> Bruno<br>
<br>
well, as the above mentioned doc says<br>
...<br>
Matrices and arrays can be composed of elements of most any MATLAB data type as long as all elements in the matrix are of the same type. If you do include elements of unlike classes when constructing a matrix, MATLAB converts some elements so that all elements of the resulting matrix are of the same type. <br>
...<br>
that's the WITHIN rule DURING construction of a matrix when nothing is known about it, yet...<br>
<br>
again<br>
<br>
r=[{} 1 2 3];<br>
<br>
1) construct the matrix = WITHIN: [{} 1 2 3];<br>
2) assign the matrix = BETWEEN: r = ANS<br>
in this case: r has NO subscripts, so it is just the ans...<br>
if, however, the lhs comes with subscripts, ML checks for consistency<br>
BETWEEN the two (lhs = rhs) containers...<br>
<br>
urs

Sat, 23 May 2009 13:51:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651862
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv8th9$166$1@fred.mathworks.com>...<br>
> "Bruno Luong"<br>
> > Humm it is clearer but not perfect, because why this doesn't work:<br>
> > >> a={1}<br>
> > a = <br>
> > [1]<br>
> > >> class(a)<br>
> > ans =<br>
> > cell<br>
> > >> a(1)=2<br>
> > ??? Conversion to cell from double is not possible.<br>
> > <br>
> > I'm still confused. It seems the example I gave above Matlab succeeds to convert somehow double to cell? Why now it can't...<br>
> <br>
> well,<br>
> in your first case, ML knows nothing about the content of the container during execution and simply converts all its entries (=within container) according to some (published) rules...<br>
> <br>
> <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
<br>
No, this page specifically gives a table of 5 data types for which mixedtype concatenation is valid. Type 'cell' is not among them

Sat, 23 May 2009 14:04:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651863
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv8udd$pdc$1@fred.mathworks.com>...<br>
<br>
> Matrices and arrays can be composed of elements of most any MATLAB data type as long as all elements in the matrix are of the same type. If you do include elements of unlike classes when constructing a matrix, MATLAB converts some elements so that all elements of the resulting matrix are of the same type. <br>
> ...<br>
> that's the WITHIN rule DURING construction of a matrix when nothing is known about it, yet...<br>
<br>
This also doesn't explain why the following does not work<br>
<br>
>> a=num2cell(eye(2))<br>
<br>
a = <br>
<br>
[1] [0]<br>
[0] [1]<br>
<br>
>> b=eye(2)<br>
<br>
b =<br>
<br>
1 0<br>
0 1<br>
<br>
>> [a,b]<br>
??? Error using ==> horzcat<br>
CAT arguments dimensions are not consistent.

Sat, 23 May 2009 14:12:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651865
us
"Matt " <xys@whatever.com> wrote in message <gv8v05$355$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv8th9$166$1@fred.mathworks.com>...<br>
> > "Bruno Luong"<br>
> > > Humm it is clearer but not perfect, because why this doesn't work:<br>
> > > >> a={1}<br>
> > > a = <br>
> > > [1]<br>
> > > >> class(a)<br>
> > > ans =<br>
> > > cell<br>
> > > >> a(1)=2<br>
> > > ??? Conversion to cell from double is not possible.<br>
> > > <br>
> > > I'm still confused. It seems the example I gave above Matlab succeeds to convert somehow double to cell? Why now it can't...<br>
> > <br>
> > well,<br>
> > in your first case, ML knows nothing about the content of the container during execution and simply converts all its entries (=within container) according to some (published) rules...<br>
> > <br>
> > <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
> <br>
> No, this page specifically gives a table of 5 data types for which mixedtype concatenation is valid. Type 'cell' is not among them<br>
<br>
yes, but  like other logical/numeric/char data objects  it is an indexed(!) based container...<br>
<br>
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f247534.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f247534.html</a><br>
<br>
in contrast, just try<br>
<br>
[struct('a','a'),1,2]<br>
<br>
again, this whole thing  always  made a lot of sense to me...<br>
however, in a way i can also agree with you two wellknown CSSMsyntax purists:<br>
rather than implementing a arrayconstructionruleforunlikedataobjects, TMW might as well just have decided to error out by default if such a construct is encountered during runtime...<br>
<br>
urs

Sat, 23 May 2009 14:19:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651867
Bruno Luong
Still not understand. Us seems the only one who understand what is going on. <br>
<br>
Just few more examples:<br>
<br>
>> C=[{1} {2} 3]<br>
<br>
C = <br>
<br>
[1] [2] [3]<br>
<br>
>> isequal(C,{1 2 3})<br>
<br>
ans =<br>
<br>
1<br>
<br>
>> isequal(C,[{1} {2} {3}])<br>
<br>
ans =<br>
<br>
1<br>
<br>
>> S = [struct() struct()]<br>
<br>
S = <br>
<br>
1x2 struct array with no fields.<br>
<br>
>> S = [struct() 1]<br>
??? Error using ==> horzcat<br>
The following error occurred converting from double to struct:<br>
Error using ==> struct<br>
Conversion to struct from double is not possible.<br>
<br>
>> C = [{} 1]<br>
<br>
C = <br>
<br>
[1]<br>
<br>
>><br>
<br>
Confused Bruno

Sat, 23 May 2009 14:20:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651868
us
"Matt " <xys@whatever.com> wrote in message <gv8voi$kg2$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv8udd$pdc$1@fred.mathworks.com>...<br>
> <br>
> > Matrices and arrays can be composed of elements of most any MATLAB data type as long as all elements in the matrix are of the same type. If you do include elements of unlike classes when constructing a matrix, MATLAB converts some elements so that all elements of the resulting matrix are of the same type. <br>
> > ...<br>
> > that's the WITHIN rule DURING construction of a matrix when nothing is known about it, yet...<br>
> <br>
> This also doesn't explain why the following does not work<br>
> <br>
> >> a=num2cell(eye(2))<br>
> <br>
> a = <br>
> <br>
> [1] [0]<br>
> [0] [1]<br>
> <br>
> >> b=eye(2)<br>
> <br>
> b =<br>
> <br>
> 1 0<br>
> 0 1<br>
> <br>
> >> [a,b]<br>
> ??? Error using ==> horzcat<br>
> CAT arguments dimensions are not consistent.<br>
<br>
but  matt  this is another story, altogether, as YOU very well know...<br>
<br>
:)<br>
urs

Sat, 23 May 2009 14:23:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651869
Bruno Luong
"us " <us@neurol.unizh.ch> wrote in message <gv907h$jee$1@fred.mathworks.com>...<br>
<br>
> <br>
> again, this whole thing  always  made a lot of sense to me...<br>
<br>
Good for you, then here a little test. Without trying, do you know what will happen with this:<br>
<br>
C = [1 2 3 {}]<br>
<br>
Bruno

Sat, 23 May 2009 14:29:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651871
us
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv90kl$ek3$1@fred.mathworks.com>...<br>
> Still not understand. Us seems the only one who understand what is going on. <br>
> <br>
> Just few more examples:<br>
> <br>
> >> C=[{1} {2} 3]<br>
> <br>
> C = <br>
> <br>
> [1] [2] [3]<br>
> <br>
> >> isequal(C,{1 2 3})<br>
> <br>
> ans =<br>
> <br>
> 1<br>
> <br>
> >> isequal(C,[{1} {2} {3}])<br>
> <br>
> ans =<br>
> <br>
> 1<br>
> <br>
> >> S = [struct() struct()]<br>
> <br>
> S = <br>
> <br>
> 1x2 struct array with no fields.<br>
> <br>
> >> S = [struct() 1]<br>
> ??? Error using ==> horzcat<br>
> The following error occurred converting from double to struct:<br>
> Error using ==> struct<br>
> Conversion to struct from double is not possible.<br>
> <br>
> >> C = [{} 1]<br>
> <br>
> C = <br>
> <br>
> [1]<br>
> <br>
> >><br>
> <br>
> Confused Bruno<br>
<br>
but, bruno, that is EXACTLY(!?!) what i'd expect...<br>
urs<br>
<br>
ps: i am clearly NOT brainwashed by TMW, as my recent CSSM trackrecord (re recent hoodlumish contest) clearly documents...

Sat, 23 May 2009 14:38:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651873
Bruno Luong
"us " <us@neurol.unizh.ch> wrote in message <gv917e$l86$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv90kl$ek3$1@fred.mathworks.com>...<br>
<br>
> <br>
> ps: i am clearly NOT brainwashed by TMW<br>
<br>
Yes you do... ;) You, Jos, Matt Fig, Matt, John, Roger, James, Yi Cao, Peter, and few others...<br>
<br>
Bruno

Sat, 23 May 2009 14:43:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651874
us
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv90s5$sqo$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv907h$jee$1@fred.mathworks.com>...<br>
> <br>
> > <br>
> > again, this whole thing  always  made a lot of sense to me...<br>
> <br>
> Good for you, then here a little test. Without trying, do you know what will happen with this:<br>
> <br>
> C = [1 2 3 {}]<br>
> <br>
> Bruno<br>
<br>
yes, of course,...<br>
;)<br>
<br>
us

Sat, 23 May 2009 14:46:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651875
Bruno Luong
"us " <us@neurol.unizh.ch> wrote in message <gv921l$cvv$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv90s5$sqo$1@fred.mathworks.com>...<br>
> > "us " <us@neurol.unizh.ch> wrote in message <gv907h$jee$1@fred.mathworks.com>...<br>
> > <br>
> > > <br>
> > > again, this whole thing  always  made a lot of sense to me...<br>
> > <br>
> > Good for you, then here a little test. Without trying, do you know what will happen with this:<br>
> > <br>
> > C = [1 2 3 {}]<br>
> > <br>
> > Bruno<br>
> <br>
> yes, of course,...<br>
> ;)<br>
> <br>
<br>
Too strong... hat!<br>
<br>
Bruno, still confused

Sat, 23 May 2009 14:51:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651876
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv907h$jee$1@fred.mathworks.com>...<br>
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
> > <br>
> > No, this page specifically gives a table of 5 data types for which mixedtype concatenation is valid. Type 'cell' is not among them<br>
> <br>
> yes, but  like other logical/numeric/char data objects  it is an indexed(!) based container...<br>
<br>
But there is nothing in the page you referenced (that I found) that the concatenation rule applies generally to indexed based classes. It says that there are exactly 5 types for which it is applies:<br>
<br>
"The following table shows the five classes you can concatenate with an unlike type without generating an error (that is, with the exception of character and logical). "

Sat, 23 May 2009 15:14:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651880
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv90mi$i8h$1@fred.mathworks.com>...<br>
<br>
> > This also doesn't explain why the following does not work<br>
> > <br>
> > >> a=num2cell(eye(2))<br>
> > <br>
> > a = <br>
> > <br>
> > [1] [0]<br>
> > [0] [1]<br>
> > <br>
> > >> b=eye(2)<br>
> > <br>
> > b =<br>
> > <br>
> > 1 0<br>
> > 0 1<br>
> > <br>
> > >> [a,b]<br>
> > ??? Error using ==> horzcat<br>
> > CAT arguments dimensions are not consistent.<br>
> <br>
> but  matt  this is another story, altogether, as YOU very well know...<br>
<br>
As far as I can tell, urs, this is not documented concatenation behavior, so I really don't know why this is another story or what to expect at all. It seems clear after experimentation that @horzcat/cell() will always transform whole matrices to cells<br>
<br>
<br>
>> [{},uint8(eye(2)), single(eye(2))]<br>
<br>
ans = <br>
<br>
[2x2 uint8] [2x2 single]<br>
<br>
but that seems very different from concat operations like the following where the transformation is done element by element<br>
<br>
>> [uint16(eye(2)), uint8(eye(2))], whos ans<br>
Warning: Concatenation with dominant (leftmost) integer class may overflow other operands on<br>
conversion to return class. <br>
<br>
ans =<br>
<br>
1 0 1 0<br>
0 1 0 1<br>
<br>
Name Size Bytes Class Attributes<br>
<br>
ans 2x4 16 uint16

Sat, 23 May 2009 15:19:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651881
us
"Matt " <xys@whatever.com> wrote in message <gv92gl$ce4$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv907h$jee$1@fred.mathworks.com>...<br>
> <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
> > > <br>
> > > No, this page specifically gives a table of 5 data types for which mixedtype concatenation is valid. Type 'cell' is not among them<br>
> > <br>
> > yes, but  like other logical/numeric/char data objects  it is an indexed(!) based container...<br>
> <br>
> But there is nothing in the page you referenced (that I found) that the concatenation rule applies generally to indexed based classes. It says that there are exactly 5 types for which it is applies:<br>
> <br>
> "The following table shows the five classes you can concatenate with an unlike type without generating an error (that is, with the exception of character and logical). "<br>
<br>
but, matt!<br>
implicit, explicit...<br>
<br>
again, bruno, matt, let me reiterate this train of thoughts:<br>
<br>
 i understand (at least, i think so; and our coding history has shown so) the arraycreation type casting bit (within vs between)...<br>
 i understand that the very syntax purists (like the obvious two of you) would rather see an early bailout during creation of arrays of unlike data objects...<br>
 it is a fact of life (again), that TMW decided (a very long time ago) to do it this way (at least they published some rules), which CSSMers have to live with...<br>
<br>
urs

Sat, 23 May 2009 15:35:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651883
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv9455$m63$1@fred.mathworks.com>...<br>
<br>
>  i understand that the very syntax purists (like the obvious two of you) would rather see an early bailout during creation of arrays of unlike data objects...<br>
<br>
<br>
Not me. I much prefer silent casting.

Sat, 23 May 2009 15:48:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651884
us
"Matt " <xys@whatever.com> wrote in message <gv9536$jgf$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv9455$m63$1@fred.mathworks.com>...<br>
> <br>
> >  i understand that the very syntax purists (like the obvious two of you) would rather see an early bailout during creation of arrays of unlike data objects...<br>
> <br>
> <br>
> Not me. I much prefer silent casting.<br>
<br>
hmm  [mat,'t']  but that IS exactly what 1) this thread is about and 2) what ML 'tries' to do according to the published rules...<br>
<br>
us

Sat, 23 May 2009 15:59:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651886
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv95rh$73o$1@fred.mathworks.com>...<br>
> "Matt " <xys@whatever.com> wrote in message <gv9536$jgf$1@fred.mathworks.com>...<br>
> > "us " <us@neurol.unizh.ch> wrote in message <gv9455$m63$1@fred.mathworks.com>...<br>
> > <br>
> > >  i understand that the very syntax purists (like the obvious two of you) would rather see an early bailout during creation of arrays of unlike data objects...<br>
> > <br>
> > <br>
> > Not me. I much prefer silent casting.<br>
> <br>
> hmm  [mat,'t']  but that IS exactly what 1) this thread is about and 2) what ML 'tries' to do according to the published rules...<br>
<br>
No, the question originally posed by Bruno is about whether the result of [{} 1 2 3] is documented behavior of horzcat(). I still hold that it is not (or rather that I haven't seen the doc).<br>
<br>
You seem to think it is inferable that conversion of a matrix to a cell should result in a single cell, as we've seen in expressions like<br>
<br>
<br>
[{}, eye(3)]<br>
<br>
ans = <br>
<br>
[3x3 double]<br>
<br>
<br>
But without documentation to the contrary, I still don't see why it shouldn't/couldn't have resulted in <br>
<br>
ans = <br>
<br>
[1] [0] [0]<br>
[0] [1] [0]<br>
[0] [0] [1]

Sat, 23 May 2009 16:27:01 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651896
us
"Matt " <xys@whatever.com> wrote in message <gv96g6$gvu$1@fred.mathworks.com>...<br>
> "us " <us@neurol.unizh.ch> wrote in message <gv95rh$73o$1@fred.mathworks.com>...<br>
> > "Matt " <xys@whatever.com> wrote in message <gv9536$jgf$1@fred.mathworks.com>...<br>
> > > "us " <us@neurol.unizh.ch> wrote in message <gv9455$m63$1@fred.mathworks.com>...<br>
> > > <br>
> > > >  i understand that the very syntax purists (like the obvious two of you) would rather see an early bailout during creation of arrays of unlike data objects...<br>
> > > <br>
> > > <br>
> > > Not me. I much prefer silent casting.<br>
> > <br>
> > hmm  [mat,'t']  but that IS exactly what 1) this thread is about and 2) what ML 'tries' to do according to the published rules...<br>
> <br>
> No, the question originally posed by Bruno is about whether the result of [{} 1 2 3] is documented behavior of horzcat(). I still hold that it is not (or rather that I haven't seen the doc).<br>
> <br>
> You seem to think it is inferable that conversion of a matrix to a cell should result in a single cell, as we've seen in expressions like<br>
> <br>
> <br>
> [{}, eye(3)]<br>
> <br>
> ans = <br>
> <br>
> [3x3 double]<br>
> <br>
> <br>
> But without documentation to the contrary, I still don't see why it shouldn't/couldn't have resulted in <br>
> <br>
> ans = <br>
> <br>
> [1] [0] [0]<br>
> [0] [1] [0]<br>
> [0] [0] [1]<br>
<br>
hmm... mat...<br>
<br>
[{}, eye(3)]<br>
% yields<br>
% ans = [3x3 double]<br>
% which is the same as > eye(3) WITHIN a matrix of cells {} > {eye(3)}<br>
{eye(3)}<br>
% ans = [3x3 double]<br>
<br>
i just don't see what is wrong with this EXPECTED behavior...<br>
<br>
urs

Sat, 23 May 2009 16:40:18 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651898
Matt Fig
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8nju$kvn$1@fred.mathworks.com>...<br>
> This syntax works it is beyond my expectation! Is it documented somewhere?<br>
> <br>
> >> [{} 1 2 3]<br>
> <br>
> ans = <br>
> <br>
> [1] [2] [3]<br>
> <br>
> % To me the correct syntax is<br>
> <br>
> >> [{} {1 2 3}]<br>
> <br>
> Bruno<br>
<br>
<br>
Wow, I think num2cell is going to see a little less runtime around my PC! I don't quite understand all of the subtleties of the other examples in this thread yet (I just woke up!), but that is a cool discovery. What were you trying to do when you found that?

Sat, 23 May 2009 16:45:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651899
Matt
"us " <us@neurol.unizh.ch> wrote in message <gv984l$s21$1@fred.mathworks.com>...<br>
> "Matt " <xys@whatever.com> wrote in message <gv96g6$gvu$1@fred.mathworks.com>...<br>
> > "us " <us@neurol.unizh.ch> wrote in message <gv95rh$73o$1@fred.mathworks.com>...<br>
> > > "Matt " <xys@whatever.com> wrote in message <gv9536$jgf$1@fred.mathworks.com>...<br>
> > > > "us " <us@neurol.unizh.ch> wrote in message <gv9455$m63$1@fred.mathworks.com>...<br>
> > > > <br>
> > > > >  i understand that the very syntax purists (like the obvious two of you) would rather see an early bailout during creation of arrays of unlike data objects...<br>
> > > > <br>
> > > > <br>
> > > > Not me. I much prefer silent casting.<br>
> > > <br>
> > > hmm  [mat,'t']  but that IS exactly what 1) this thread is about and 2) what ML 'tries' to do according to the published rules...<br>
> > <br>
> > No, the question originally posed by Bruno is about whether the result of [{} 1 2 3] is documented behavior of horzcat(). I still hold that it is not (or rather that I haven't seen the doc).<br>
> > <br>
> > You seem to think it is inferable that conversion of a matrix to a cell should result in a single cell, as we've seen in expressions like<br>
> > <br>
> > <br>
> > [{}, eye(3)]<br>
> > <br>
> > ans = <br>
> > <br>
> > [3x3 double]<br>
> > <br>
> > <br>
> > But without documentation to the contrary, I still don't see why it shouldn't/couldn't have resulted in <br>
> > <br>
> > ans = <br>
> > <br>
> > [1] [0] [0]<br>
> > [0] [1] [0]<br>
> > [0] [0] [1]<br>
> <br>
> hmm... mat...<br>
> <br>
> [{}, eye(3)]<br>
> % yields<br>
> % ans = [3x3 double]<br>
> % which is the same as > eye(3) WITHIN a matrix of cells {} > {eye(3)}<br>
> {eye(3)}<br>
> % ans = [3x3 double]<br>
> <br>
<br>
Are you saying that horzcat(A,B,C,...) is equivalent to {A,B,C,...} if one of the arguments is a cell array? Apparently not, since<br>
<br>
>>horzcat({},eye(3))<br>
ans = <br>
<br>
[3x3 double]<br>
<br>
but<br>
<br>
>> {{},eye(3)}<br>
<br>
ans = <br>
<br>
{} [3x3 double]

Sat, 23 May 2009 19:05:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651923
Bruno Luong
What bother me usr is this. When we type<br>
<br>
[1:3 4 5]<br>
<br>
it gave the array of 1 to 5.<br>
<br>
Now, what happens if I do<br>
<br>
[1:3 4 {} 5]<br>
<br>
Because of the presence of {}, Matlab will interpret (or CAST or what whatever the right world)<br>
<br>
1:3 > {1:3}<br>
4 > {4}<br>
5 > {5}<br>
<br>
So it looks like MATLAB is able to convert DOUBLE array to CELL array implicitly in this build.<br>
<br>
So when I type<br>
<br>
>> C = {1}<br>
>> C(1) = 2<br>
<br>
I would expect it behaves a little bit like <br>
<br>
>> C=uint8(1)<br>
>> C(1) = pi<br>
<br>
where cast from DOUBLE to INT8 is carried out.<br>
<br>
I know that MATLAB *can* cast from class DOUBLE to CELL (while building an array), but not here: it flushes me out with the error message. To me this is an inconsistent in MATLAB behavior.<br>
<br>
And I agree with Matt, from many documents you have showed, none of them address this behavior, even that you think the contrary.<br>
<br>
Anyway, I might change my opinion later, but for now I'm not yet convinced.<br>
<br>
Thanks, it was a good discussion.<br>
<br>
Bruno

Sun, 24 May 2009 01:56:11 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651957
Steven Lord
<br>
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <br>
news:gv8rum$lea$1@fred.mathworks.com...<br>
> "us " <us@neurol.unizh.ch> wrote in message <br>
> <gv8r4e$19v$1@fred.mathworks.com>...<br>
>> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <br>
>> <gv8nju$kvn$1@fred.mathworks.com>...<br>
>> > This syntax works it is beyond my expectation! Is it documented <br>
>> > somewhere?<br>
>> ><br>
>> > >> [{} 1 2 3]<br>
>> ><br>
>> > ans =<br>
>> ><br>
>> > [1] [2] [3]<br>
<br>
This attempts to concatenate together a cell array, a double, a double, and <br>
a double. In order to do so, they need to be the same data type; since the <br>
leftmost element being concatenated is a cell array, the other elements are <br>
turned into cell arrays, and then the four cell arrays are concatenated <br>
together using normal cell array concatenation.<br>
<br>
*snip*<br>
<br>
>> > Bruno<br>
>><br>
>> it is a weel known fact of ML life<br>
>><br>
>> ...<br>
>> When MATLAB sees a subscripted assignment to an existing variable, MATLAB <br>
>> checks the class of the righthandside against the class of the <br>
>> lefthandside (LHS) variable. If different, it attempts to convert the <br>
>> righthandside (RHS) variable to the type of the LHS class.<br>
<br>
While true, that's irrelevant in this case, as we're dealing with <br>
concatenation not assignment.<br>
<br>
>> ['a' nan]<br>
>> [uint8(1) pi]<br>
>> [pi uint8(1)]<br>
>><br>
>> here some of the tech docs this is referred to<br>
>><br>
>> <a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
>> <a href="http://www.mathworks.com/support/solutions/en/data/16K5PAO/">http://www.mathworks.com/support/solutions/en/data/16K5PAO/</a><br>
>><br>
><br>
> Humm it is clearer but not perfect, because why this doesn't work:<br>
><br>
>>> a={1}<br>
><br>
> a =<br>
><br>
> [1]<br>
><br>
>>> class(a)<br>
><br>
> ans =<br>
><br>
> cell<br>
><br>
>>> a(1)=2<br>
> ??? Conversion to cell from double is not possible.<br>
><br>
> I'm still confused. It seems the example I gave above Matlab succeeds to <br>
> convert somehow double to cell? Why now it can't.<br>
<br>
The rules for concatenation and for subscripted assignment are different. <br>
It's not ideal, but that's how it works.<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com

Sun, 24 May 2009 06:39:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651973
Bruno Luong
"Steven Lord" <slord@mathworks.com> wrote in message <gva9fe$egf$1@fred.mathworks.com>...<br>
> <br>
<br>
> <br>
> The rules for concatenation and for subscripted assignment are different. <br>
> It's not ideal, but that's how it works.<br>
> <br>
<br>
That says all. A consistent answer for a nonconsistent behavior. Thanks for shedding a light Steve.<br>
<br>
Bruno

Sun, 24 May 2009 09:05:03 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#651984
us
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gvaq26$7jb$1@fred.mathworks.com>...<br>
> "Steven Lord" <slord@mathworks.com> wrote in message <gva9fe$egf$1@fred.mathworks.com>...<br>
> > <br>
> <br>
> > <br>
> > The rules for concatenation and for subscripted assignment are different. <br>
> > It's not ideal, but that's how it works.<br>
> > <br>
> <br>
> That says all. A consistent answer for a nonconsistent behavior. Thanks for shedding a light Steve.<br>
> <br>
> Bruno<br>
<br>
well, yes, quite what i said using the expression within/between...<br>
<br>
:)<br>
us

Sun, 24 May 2009 17:19:02 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#652056
Matt
"Steven Lord" <slord@mathworks.com> wrote in message <gva9fe$egf$1@fred.mathworks.com>...<br>
<br>
> This attempts to concatenate together a cell array, a double, a double, and <br>
> a double. In order to do so, they need to be the same data type; since the <br>
> leftmost element being concatenated is a cell array, the other elements are <br>
> turned into cell arrays, and then the four cell arrays are concatenated <br>
> together using normal cell array concatenation.<br>
<br>
Thanks, Steve. But what we were wondering, initially, is if this is documented anywhere. I see nothing in "doc horzcat" describing the rule for converting doubles to cells. Apparently, the conversion rule is @(x) {x}, but it could also have been @(x) num2cell(x) for example. <br>
<br>
And, according to this web page referenced above by urs, it shouldn't even be possible. <br>
<br>
<a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a><br>
<br>
According to that page, the only mixture of data types that supported for concatenation are char, double,single,logical, and integer types.<br>
<br>
<br>

Sun, 21 Mar 2010 07:34:11 +0000
Re: Comma list with leading cell
http://www.mathworks.com/matlabcentral/newsreader/view_thread/252030#728245
Kim
"us " <us@neurol.unizh.ch> wrote in message <gv8udd$pdc$1@fred.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gv8tl1$81o$1@fred.mathworks.com>...<br>
> > "us " <us@neurol.unizh.ch> wrote in message <gv8t0d$rm7$1@fred.mathworks.com>...<br>
> > <br>
> > > <br>
> > > <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html">http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/br04cfa1.html</a> <br>
<a href="http://www.wikio.com/article/badcreditpaydayloans176415445">http://www.wikio.com/article/badcreditpaydayloans176415445</a><br>
> > > <br>
> > <br>
> > But us, let us reiterate the question. Why conversion from double to cell<br>
> > <br>
> > C = {1};<br>
> > C(1) = 2<br>
> > <br>
> > is not allowed?<br>
> > <br>
> > Bruno<br>
> <br>
> well, as the above mentioned doc says<br>
> ...<br>
> Matrices and arrays can be composed of elements of most any MATLAB data type as long as all elements in the matrix are of the same type. If you do include elements of unlike classes when constructing a matrix, MATLAB converts some elements so that all elements of the resulting matrix are of the same type. <br>
> ...<br>
> that's the WITHIN rule DURING construction of a matrix when nothing is known about it, yet...<br>
> <br>
> again<br>
> <br>
> r=[{} 1 2 3];<br>
> <br>
> 1) construct the matrix = WITHIN: [{} 1 2 3];<br>
> 2) assign the matrix = BETWEEN: r = ANS<br>
> in this case: r has NO subscripts, so it is just the ans...<br>
> if, however, the lhs comes with subscripts, ML checks for consistency<br>
> BETWEEN the two (lhs = rhs) containers...<br>
> <br>
> urs