Is it possible to insert multidimensional arrays within table entries?

15 次查看(过去 30 天)
For example: I want to create a table with 5 rows and 2 columns. The first column is just 5 rows of doubles. Can I insert a 3x3x2 array into every row of the second column?
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-4-14
编辑:Dyuman Joshi 2023-4-14
It is possible, but technically it's a 1x1 cell array which contains the 3x3x2 double array -
data1 = rand(5, 1);
data2 = repmat({rand(3,3,2)}, 5, 1);
y=table(data1, data2)
y = 5×2 table
data1 data2 ________ ______________ 0.67046 {3×3×2 double} 0.30826 {3×3×2 double} 0.65208 {3×3×2 double} 0.8973 {3×3×2 double} 0.046877 {3×3×2 double}

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2023-4-14
I don't think an element of table can be a mutli-dimensional array, but it can be a cell that holds a multidimensional array:
% Create a cell array that will be converted to a table
c = {1,rand(3,3,2);
2,rand(3,3,2);
3,rand(3,3,2);
4,rand(3,3,2);
5,rand(3,3,2)
};
% Convert to table
t = cell2table(c)
t = 5×2 table
c1 c2 __ ______________ 1 {3×3×2 double} 2 {3×3×2 double} 3 {3×3×2 double} 4 {3×3×2 double} 5 {3×3×2 double}
% Contents of t(1,2) is a cell array
t{1,2}
ans = 1×1 cell array
{3×3×2 double}
% Contents of that cell is the 3,3,2 array
t{1,2}{:}
ans =
ans(:,:,1) = 0.0665 0.1908 0.2427 0.5777 0.5714 0.0996 0.8492 0.3431 0.9827 ans(:,:,2) = 0.2977 0.2038 0.3317 0.9687 0.0533 0.0859 0.9267 0.6033 0.2975
I'm therefore not sure if a table would be the most appropriate way to store these data, as opposed to a cell array directly.
(But, I could be wrong about a more direct way to store the array.)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by