Effacer les filtres
Effacer les filtres

Creating a 3D table (or equivalent)

158 vues (au cours des 30 derniers jours)
Peter
Peter le 16 Avr 2020
Commenté : Ameer Hamza le 17 Avr 2020
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?

Réponse acceptée

Ameer Hamza
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
Peter
Peter le 17 Avr 2020
That's it, thanks again!
Ameer Hamza
Ameer Hamza le 17 Avr 2020
Glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by