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!