How to create a array or list of timetables?

11 ビュー (過去 30 日間)
Shankar Ramharack
Shankar Ramharack 2022 年 11 月 12 日
回答済み: Arjun 2024 年 10 月 1 日
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 Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by