Comma-separated assignment to a table variable
Mostrar comentarios más antiguos
The code below tests assignment by comma-separated expansion to a cell array in 3 different scenarios. In the specific case when the cell array X is the variable of a table, it fails. Why is that?
X=cell(1,3);
S.X=X;
T=table(X);
[X{:}]=deal(1,2,3) %Case (1) : works fine
[S.X{:}]=deal(1,2,3) %Case (2) : works fine
[T.X{:}]=deal(1,2,3) %Case (3) : fails
9 comentarios
Stephen23
hace 8 minutos
Table overloads both subsref and subsasgn. Its indexing is nothing like any other class.
Why does the second call to deal result in three copies of the same displayed output?
X = cell(1,3);
T = table(X);
[X{:}] = deal(1,2,3)
[T.X{1},T.X{2},T.X{3}] = deal(1,2,3)
Matt J
hace alrededor de 2 horas
Matt J
hace alrededor de 4 horas
dpb
hace alrededor de 3 horas
I note there that the table/timetable are notably missing the "Use in comma separated lists" line item in the "Intended Use" column....guess it also shows how long it's been since I did more than look up individual functions in the doc -- I had forgotten about that overview page existing.
While I'd never attempted the addressing to a table in that fashion and wouldn't have thought of doing so in all likelihood anyway, I'll confess I don't know enough about the internals for it to be apparent to me why it couldn't be done; I would presume adding the additional complexity on top of existing logic could be a performance issue in adding yet another layer of complexity.
Respuestas (1)
The table is a one-row cell array in one vairable so it can be assigned directly as a cell can be...
X=cell(1,3);
T=table(X)
T.X={1 2 3}
No need for deal() here as the dot-X notation returns the cell array in its entirety. Of course, in a table cell, it can contain anything any other cell can
T.X(1:2)={1 2};
T.X(3)={'Fred Flintstone'}
T.X
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!