Is this a bug? Accessing table variables in cell format by row indices (R2015a)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kouichi Nakamura
el 30 de Dic. de 2015
Respondida: Kouichi Nakamura
el 1 de En. de 2016
I have a trouble in understanding a syntax to access table contents (MATLAB R2015a).
In the following example, you can access 1st, 2nd and 5th rows of table t just fine.
>> a = (1:10)';
>> t = table(a);
>> class(t.a)
ans =
double
>> t.a([1,2,5])
ans =
1
2
5
However, when the table values are in cell array like below, although the cell array c and the column of table T.c appear to be identical, I cannot access to their content in the same way with row indices; that is, while c{[1,2,5]} can return all the three values, T.c{[1,2,5]} only returns the value for T.c{1} in this case.
I wonder if this is some kind of bug. If it is not, could someone explain me the logic behind this weird-looking behaviour?
>> c = num2cell(a);
% accessing cell array
>> c{[1,2,5]}
ans =
1
ans =
2
ans =
5
>> A = [c{[1,2,5]}]'
A =
1
2
5
% accessing table variable that is in cell format
>> T = table(c);
class(T.c)
ans =
cell
>> T.c{[1,2,5]}
ans =
1
>> B= [T.c{[1,2,5]}]'
B =
1
0 comentarios
Respuesta aceptada
Sean de Wolski
el 31 de Dic. de 2015
In R2015b I see the expected results for both of your operations
t.c{[1,2,5]}
ans =
0.8147
ans =
0.9058
ans =
0.6324
[t.c{[1 2 5]}]
ans =
0.8147 0.9058 0.6324
1 comentario
Peter Perkins
el 31 de Dic. de 2015
Sean is correct, R2015b will give you what you're looking for. It is one of many nice benefits of the new MATLAB Execution Engine .
Prior to that
[c1,c2,c5] = T.c{[1,2,5]}
should do what you want.
Más respuestas (1)
Ver también
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!