Is this a bug? Accessing table variables in cell format by row indices (R2015a)
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kouichi Nakamura
le 30 Déc 2015
Réponse apportée : Kouichi Nakamura
le 1 Jan 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 commentaires
Réponse acceptée
Sean de Wolski
le 31 Déc 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 commentaire
Peter Perkins
le 31 Déc 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.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!