How to create a array or list of timetables?
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to create an array of timetables in matlab similar to how I can create a list of time-indexed dataframes in python.
Currently I have the follwing:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1190753/image.png)
I want to create a collection of timetables so I can iterate through a list and select different timetables.
1 Commento
dpb
il 12 Nov 2022
Simply store them into a cell array...addressing then gets a little cumbersome, but is doable.
Risposte (1)
Arjun
il 1 Ott 2024
Hi @Shankar,
As per my understanding, you want to store multiple timetables in an array or a list type of setting in MATLAB.
In MATLAB, you cannot store timetables directly into an array but as an alternate way you can store them in a cell array as it can store different type of data including complex objects like timetables.
You can refer to the code below for better understanding:
% Create dummy data for generating two time tables
time1 = datetime(2023, 1, 1) + days(0:4);
time2 = datetime(2023, 1, 1) + days(0:4);
data1 = rand(5, 1);
data2 = rand(5, 1);
% Create two timetable from the above data
tt1 = timetable(time1', data1, 'VariableNames', {'Data1'});
tt2 = timetable(time2', data2, 'VariableNames', {'Data2'});
% Use cell array to store timetables
timetableArray = {tt1, tt2};
% Iterate over the cell array of timetables to perform operations
for i = 1:length(timetableArray)
currentTimetable = timetableArray{i};
disp(['Timetable ', num2str(i), ':']);
disp(currentTimetable);
end
You can have a look at the documentation of cell arrays for better understanding: https://www.mathworks.com/help/matlab/cell-arrays.html
I hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Dates and Time 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!