MATLAB: How to create a column for occupied and unoccupied in which each value in the column is a linspace timeline? I understand the timeline length for each value will be different.

create timelinelinspace datetime

I need to keep historical data for when a room is occupied and unoccipied in order to predict occupancy in the near future. In order to do so I am trying to create a timeline (by the minute) using date-time format. Am I on the right track here? Should I be using "datestr()"? Thanks in advance.
occupied = zeros(N,1); %vector for times when the room is occupied
unoccupied = zeros(N,1); %vector for times when the room is unoccupied
for i=1:N %looping the build vectors
occupied(i)=linspace(starttime(i),endtime(i));
j=i+1;
unoccupied(i)=linspace(endtime(i),starttime(j));
end

Best Answer

Consider storing your data in a timetable. The first minute a room becomes occupied, assign it the value 1. The first minute it becomes unoccupied, assign it the value 0. Then retime the timetable to use the 'minutely' time basis and the 'prev' method.
Related Question