How to reference a cell from a table within a table
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Peter Perkins
am 17 Jul. 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 Kommentare
Dirk Engel
am 12 Jul. 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 Kommentare
Voss
am 12 Jul. 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{:,:}
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!