Check for a certain variable in a cell filled with different timetables
조회 수: 2 (최근 30일)
표시 이전 댓글
Hello MathWorks Community.
I have a 6x1 cell which inherits 6 timetables with different sizes called "data".
The columns in these different timetables are all named unique in a way e.g. "var1" ... "varX" but shuffled randomly between the timetables.
If i know the correct timetable of var1, "data{1}.var1" gives me the according var1 data.
Right now i try to find the position/timetable of a specified variable. But how do i do that?
Thanks in advance.
P.S: Image illustrates the structure im working with.
댓글 수: 0
채택된 답변
Mitch Lautigar
2022년 5월 6일
What you need to do is to index through every timetable. Since data is a structure, you can use fields command to get all of the fields inside data, and then index through each timetable. This looks like the following.
field_names = string(fieldnames(data));
for i = 1:length(field_names)
curr_timetable = data.(field_names(I));
%input logic to handle timetables here
end
This will let you index through the starting array, and then it's a matter of looking at the variable names in the table. I believe the property you are looking for is "head" (source: https://www.mathworks.com/help/matlab/timetables.html )
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!