# Is this a bug? Accessing table variables in cell format by row indices (R2015a)

1 view (last 30 days)
Kouichi Nakamura on 30 Dec 2015
Answered: Kouichi Nakamura on 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

Sean de Wolski on 31 Dec 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
Peter Perkins on 31 Dec 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.

Kouichi Nakamura on 1 Jan 2016
Thank you, guys. Indeed, R2015b gave the expected results! Now I clarified that the version I used was R2015a.
Also, thank you, Peter, for the alternative syntax. For some reason, R2015b Mac is not very stable in my environment, so this trick is very helpful.

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!