How to create a array or list of timetables?

15 次查看(过去 30 天)
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 个评论
dpb
dpb 2022-11-12
Simply store them into a cell array...addressing then gets a little cumbersome, but is doable.

请先登录,再进行评论。

回答(1 个)

Arjun
Arjun 2024-10-1
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!

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by