How to reference a cell from a table within a table
조회 수: 38 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Peter Perkins
2023년 7월 17일
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
Dirk Engel
2023년 7월 12일
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
Voss
2023년 7월 12일
t = table(table(rand(5,1), rand(5,1)), table(rand(5,1)), 'VariableNames', {'InnerTable1', 'InnerTable2'})
temp = varfun(@(t)t{3,:},t)
data = temp{:,:}
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!