MATLAB: Plot ode with tspan in date format

dateaxisdatetickode45 plot

function dv = coronabook(t,v)
dv = zeros (8,1); % a column vector
beta=0.487;gamma1=1/7;gamma2=1/7;gamma3=1/14;epislon1=0.3;epislon2=0.2;
epislon3=0.1;alpha1= 0.5; sigma1=1/7;sigma2=0.574;p=0.7;m=0.029;
k=0.058;lambda1=0.053;lambda2=0.0103;theta=0.005;g=k+gamma1+lambda1;
h=gamma2+theta;q=gamma3+lambda2;
betabar=alpha1*beta;f=(1-p)*sigma1+p*sigma2;
dv(1) = -betabar*(v(3)+epislon1*v(4)+epislon2*v(5)+epislon3*v(6))*v(1);
dv(2) = betabar*(v(3)+epislon1*v(4)+epislon2*v(5)+epislon3*v(6))*v(1)-f*v(2);
dv(3) = (1-p)*sigma1*v(2)-g*v(3);
dv(4) = p*sigma2*v(2)-m*v(4);
dv(5) = m*v(4)-h*v(5);
dv(6) = k*v(3)+theta*v(5)-q*v(6);
dv(7) = gamma1*v(3)+gamma2*v(5)+gamma3*v(6);
dv(8) = lambda1*v(3)+lambda2*v(6);
[t,v] = ode45 (@coronabook,[1 350],[1 1e-6 1e-7 5e-9 0 0 0 0]);
plot (t,v (:,2),'b','LineWidth',1.5)
xlabel ('Time (Days)'); ylabel ('Infected population');
grid on
Please I need help on how to plot the above ode with the tspan in date format. I want the interval of t to run in date format of the form 29 Feb 2020 to 31 Jan 2021 instead of 1 to 350 day.
Totalcases = [1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 8 12 25 30 40 44 51 65 97 111 131 139 174 184 210 214 232 238 254 276 288 305 318 323 343 ...
373 407 442 493 542 627 665 782 873 981 1095 1182 1273 1337 1532 1728 1932 2170 2388 2558 2802 2950 3145 3526 3912 4151 4399 4641 4787 ...
4971 5162 5445 5621 5959 6175 6401 6477 7016 7261 7526 7839 8068 8344 8733 8915 9302 9855 10162 10578 10819 11166 11516 11844 12233 12486 ...
12801]/Totalpopulation;
figure 2
plot(t,J+H+H_diagnosed,'LineWidth',2)
hold on
stem(t(1:1/step:size(Totalcases,2)/step),Totalcases)
xlim([t(1) t(end)])
dateaxis('x',2,'02/29/2020')
ylim([0 6.5e-5])
title('Infected: Model vs. Data')
xlabel('Time (days)')
ylabel('Cases (fraction of the population)')
grid
if plotPDF==1
set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperPosition', [0 0 16 10]);
set(gcf, 'PaperSize', [16 10]); % dimension on x axis and y axis resp.
print(gcf,'-dpdf', ['Positivi_diagnosticati.pdf'])
end
Please I also need help concerning the second code. The second code is part of a long code I am using. I plot the code and it run. But, the dates on the x-axis are together. I want to rotate them. I need code on how to rotate them. The Totalcases in the second code are not in date format. Thank you.

Best Answer

Try (untested but should work):
[t,v] = ode45 (@coronabook,[1 350],[1 1e-6 1e-7 5e-9 0 0 0 0]);
startDate = datetime(2020, 2, 28);
plot (startDate + days(t),v (:,2),'b','LineWidth',1.5)