Borrar filtros
Borrar filtros

Indexing a cell array in a table

11 visualizaciones (últimos 30 días)
Michael
Michael el 9 de Abr. de 2015
Respondida: Debarati Banerjee el 13 de Abr. de 2015
When I have a table where one of the variables is a cell array, indexing using curly brackets into that column does not seem to work as expected.
myCell = {'a';'b';'c';'d';'e'};
myTable = table(myCell)
isequal(myCell{1},vertcat(myTable.myCell{:})) % Should be false, but returns true
isequal(vertcat(myCell{:}),vertcat(myTable.myCell{:})) % Should be true, but returns false
It seems to me that using curly brackets to index into a cell array returns only the first cell indexed.
isequal(myTable.myCell{2:3},myCell{2}) % returns true
This seems like a bug, or am I missing something?

Respuesta aceptada

Debarati Banerjee
Debarati Banerjee el 13 de Abr. de 2015
When you try to access contents of multiple cells, MATLAB creates a comma-separated list. Because each cell can contain a different type of data, you cannot assign this list to a single variable. However, you can assign the list to the same number of variables as cells. MATLAB assigns to the variables in column order.
Check the following link for more information:
Modifying the code as
myCell = {'a';'b';'c';'d';'e'};
myTable = table(myCell)
isequal(myCell{1},vertcat(myTable.myCell))
isequal(vertcat(myCell),vertcat(myTable.myCell))
seems to work.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by