Check for a certain variable in a cell filled with different timetables

3 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Mitch Lautigar
Mitch Lautigar le 6 Mai 2022
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 )

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by