How to reference a cell from a table within a table
38 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Peter Perkins
il 17 Lug 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 Commenti
Dirk Engel
il 12 Lug 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 Commenti
Voss
il 12 Lug 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{:,:}
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!