Creating a 3D table (or equivalent)
163 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Ameer Hamza
le 16 Avr 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!