Creating a 3D table (or equivalent)

158 次查看(过去 30 天)
Is it possible to create a 3D table to represent a stack of tables? I have N number of tables, each of which has the same number of columns and rows, the same column and row names, and the same type of data in each column. I'm looking for a way to stack them, so that each data set can be referenced by either it's string name, or the index in the stack.
You can create a table of tables like this:
initTable1 = table('Size',[6,4],'VariableTypes',{'string','double','double','double'})
initTable2 = table('Size',[6,4],'VariableTypes',{'string','double','double','double'})
initTable3 = table('Size',[6,4],'VariableTypes',{'string','double','double','double'})
stackTable = table(initTable1,initTable2,initTable3)
But I want to be able to define the number of tables that are included in 'stackTable' on the fly. How would I initialize such a table? The number of stacked tables will not be static (and will probably be on the order of 6-30 stacked tables). If it matters, the size of each individual table is relativly small.
I'm trying to do this because I'd like to be able to reference each table by either it's string name or by it's index, similar to how you can access each field in a traditional 2D table.
If this is not possible, or not advised, is there a better alternative?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-16
Instead of making tables of tables, I recommend making a cell array of tables because stacking makes more sense in that case. For example
initTable1 = table('Size',[6,4],'VariableTypes',{'string','double','double','double'});
initTable2 = table('Size',[6,4],'VariableTypes',{'string','double','double','double'});
initTable3 = table('Size',[6,4],'VariableTypes',{'string','double','double','double'});
stackTable = {initTable1, initTable2, initTable3};
Now you can get the data using the index of the table in stack and the variable name.
stackTable{index_in_stack}.variableName
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by