Indexing a cell array in a table
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuesta aceptada
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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing 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!