I'm having some trouble interpretting your data. I'm not sure I understood completely how the dates align with the times.
For example, the first data point is March 5, 2021 and 30.36361 hours and the 199th data point is March 5, 2021 and 32.82417 hours, but the 200th data point is March 10, 2021 and 57.55306 hours. More than 25 hours elapsed between March 5 and March 10, so there is some detail I'm clearly missing.
Regardless: There isn't really a great way (currently) in MATLAB to create two x-axes. You have two (not great) options:
- Create two overlapping axes, and make sure to align them carefully with one another.
- Manually position text objects to "fake" a second x-axis.
In addition, there isn't a built-in way to create a discontinuous datetime ruler (as in, a ruler that uses datetimes as input data, but has gaps in time along the ruler). The only way to recreate this would be to manually create this effect by setting the desired tick values and labels.
Here is my attempt at interpretting what you are trying to create, using the first approach (two overlapping axes):
tbl = readtable('matlabproblem.xlsx');
tbl.Time = hours(tbl.Time);
layout = tiledlayout(1,1);
plot(ax1, tbl.Time, tbl.Temp);
p = plot(ax2, tbl.Time, tbl.Temp);
ax2.XAxisLocation = 'top';
ax2.XAxis.Visible = true;
ax2.YAxisLocation = 'right';
ax2.YAxis.Visible = true;
alldates = unique(tbl.Date);
centers = tbl.Time(1:numel(alldates));
labels = string(alldates);
for d = 1:numel(alldates)
times = tbl.Time(tbl.Date == alldates(d));
centers(d) = mean([min(times) max(times)]);