Create a logistical variable based on time range

1 view (last 30 days)
William Garrett
William Garrett on 22 Feb 2020
Edited: dpb on 23 Feb 2020
I have some air quality data from an office ranging from the 9th October to the 21st October.
I am trying to understand how air quality behaves when nobody is in the office. Therefore I need to seperate out the data from when nobody is in the office.
This is between 6:30pm and 6:30 am every day, apart from the 12th, 13th, 19th and 20th, when the office is empty all day (weekends).
I am assuming I can use a timerange to create a logistical variable which I can then use to index.
How do I create this logistical variable to seperate out these desired time ranges?
I have included some sample data, this is a subset because the excel file is very large in its totality
Two important things to note is that there a far more column variables in reality than I have attached and that in MATLAB the datetime variable changes from a xx/xx/xxxx xx:xx:xx to xx-xx-xxxx xx:xx:xx format
William Garrett
William Garrett on 22 Feb 2020
I have loaded the table into Matlab yes - how would the tableread function enable me to sort the data by date and time sorry?

Sign in to comment.

Accepted Answer

dpb on 22 Feb 2020
Edited: dpb on 23 Feb 2020
readtable is a convenient byway on the way to a timetable which will undoubtedly be your friend...
tt=readtable('Forum_aq_data.xlsx','ReadVariableNames',0); % read the .xlsx file, no header row
tt.Properties.VariableNames={'Time','AQ1','AQ2'}; % some at least partially meaningful names
tt=table2timetable(tt); % convert the table to a timetable
ixOffEmpty = isweekend(tt.Time) | ... % either weekend or
~isbetween(timeofday(ttforum.Time),duration("06:30:00"),duration("18:30:00")); % not between 6:30AM and 6:30 PM same day
ttEmpty=tt(ixOffEmpty,:); % save the portion wanted for analysis
Read up on how to process tables; there are many "tricks of the trade" that will ease statistics and those kinds of things immeasurably as well as grouping variables, etc., if some of the variables are things like locations, etc., Don't forget to turn those types of variables into categorical.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!