MATLAB: Converting Timetable to Individual Columns

converttabletimetable

Hello, I am trying to convert my timetable into a table with hour, day, month, and year in separate columns. This is so I can create a plot of hour with respect too another variable, if you have any ideas they would be much appreciated, thank you.

Best Answer

Hi,
Since I don't have access to the data you are trying to convert, I am going to use the air quality data included with MATLAB. Here are the steps you can try:
% Create a timetable
indoors = readtable('indoors.csv');
indoors = table2timetable(indoors);
% access the 'Time' column; times is now a datetime
times = indoors.Time;
% Create table
times_table = table(times.Hour, times.Day, times.Month, times.Year);
% The variable names appears as Var1, Var2, ... They can be changed using Properties
times_table.Properties.VariableNames = {'Hour', 'Day', 'Month', 'Year'};
You can now add the rest of the variables from timetable to the table (times_table) to complete the conversion. Hope this helps!