MATLAB: Matlab thestery: Comparison is not defined between double and datetime arrays

datetime

I'm new to Matlab, troubleshooting a comparison error by chopping it down as simple as can be. This test matrix of two rows works fine, then I copy/paste to add a third record and I get a conversion error (for the same data)!
Background: my data is for patient exams: patient, arrival time, exam start time, and I'm writing a program to determine how full the waiting room gets. If the patient isn't seen instantaneously I add them to a patient_queue (just saving their eventual start time as a placeholder). The data is in order of arrival time, so at each new row I check the queue to see if anyone's exam started in the meantime, remove them, and go from there.
Here's an example with only two patient rows (this works):
data_matrix = [1,735724.291666667,735724.322916667,735724.343750000,5; 2,735724.331250000,735724.340277778,735724.371527778,18]
patient_queue = [];
highest_wait_num = 0;
[rows, columns] = size(data_matrix);
for i = 1:rows
this_row_arrival = datetime (data_matrix(i, 2), 'ConvertFrom', 'datenum');
this_row_exam_start = datetime (data_matrix(i, 3), 'ConvertFrom', 'datenum');
now = this_row_arrival; %making a copy called 'now' for readability below
% check patient queue: if anyone left in the meantime, remove them
for j = 1:length(patient_queue)
if patient_queue{j} < now
patient_queue{j} = [];
end
end
But when I use the full data set I get an error at the if patient_queue{j} < now line:
Comparison is not defined between double and datetime arrays.
So I'm narrowing the problem, and I can even reproduce the error by taking my simple matrix of 2 records that worked, copy the second one to make a matrix of 3, like so- just swapping that in the code above makes the error(!!):
data_matrix = [1,735724.291666667,735724.322916667,735724.343750000,5;2,735724.331250000,735724.340277778,735724.371527778,18;2,735724.331250000,735724.340277778,735724.371527778,18]
What am I missing? If you're a generous soul who has a minute to try at home, here's the full code: https://gist.github.com/dianekaplan/7f755811f3880e40e170bb4438ace116

Best Answer

Is 17 (a double precision value) greater than, less than, or equal to last Tuesday (a datetime value)? Does that question make sense?
Initialize patient_queue to be an empty datetime array.
patient_queue = datetime([], [], []);
Comparing two datetime arrays is like asking if last Tuesday is greater than (after), less than (before), or equal to last Wednesday. That question does make sense.