How to create a array or list of timetables?

15 views (last 30 days)
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:
I want to create a collection of timetables so I can iterate through a list and select different timetables.
  1 Comment
dpb
dpb on 12 Nov 2022
Simply store them into a cell array...addressing then gets a little cumbersome, but is doable.

Sign in to comment.

Answers (1)

Arjun
Arjun on 1 Oct 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!

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!