Is this a bug? Accessing table variables in cell format by row indices (R2015a)
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Sean de Wolski
2015-12-31
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 个评论
Peter Perkins
2015-12-31
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.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!