How to reference a cell from a table within a table
51 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi super quick question. I have a table with another set of tables within it read from a folder. I want to plot certain rows from the table within the table, but how can I reference this in Matlab?
Thank you for any help.
0 commentaires
Réponses (2)
Peter Perkins
le 17 Juil 2023
Aron, it sounds like you have tables in a cell array in a table. Dirk is assuming you have "nested tables", which is different but also useful. Assuming you have something like this
t = table({table(rand(5,1),rand(5,1));table(rand(5,1),rand(5,1));table(rand(5,1),rand(5,1))})
you should ask yourself how you would get at those tables if the cell array were in your workspace. You'd use braces, right? S ame thing here, only on the var in the table
t.Var1{1}
t.Var1{2}(1:2,:)
Whether nested tables or tables in a cell array in a table are the right thing to use, I can't say. Both are useful, just for different purposes.
0 commentaires
Dirk Engel
le 12 Juil 2023
You can access a specific inner table by its variable name. Consider the following table with two inner tables.
t = table(table(rand(5,1), rand(5,1)), table(rand(5,1)), 'VariableNames', {'InnerTable1', 'InnerTable2'})
To access row 3 of InnerTable1, write
t.InnerTable1(3, :)
However, you can also simply write
t(3, 1)
where column index 1 refers to the outer table's first variable, which here is 'InnerTable1'.
2 commentaires
Voss
le 12 Juil 2023
t = table(table(rand(5,1), rand(5,1)), table(rand(5,1)), 'VariableNames', {'InnerTable1', 'InnerTable2'})
temp = varfun(@(t)t{3,:},t)
data = temp{:,:}
Voir également
Catégories
En savoir plus sur LaTeX 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!