Why is my plot not showing?

조회 수: 17 (최근 30일)
William Clark
William Clark 2020년 12월 14일
답변: Star Strider 2020년 12월 14일
I am trying to have Matlab create this plot, and no errors pop up in my code, but for some reason the figure will not show up and I don't know why.
tempdata1 = readcell('2020_Temp.xlsx','Range','A2:A201'); %Gather St. George data
tempSG = [tempdata1'];
tempStGeorge = tempSG(1:200);
function myODE
tspan = [1 200];
S0 = [226513, 0, 29, 0, 0, 0, 0, 0];
[t S] = ode45(@g,tspan,S0);
figure
plot(t,S(:,3),'-b')
legend('Active Cases')
axis([1 200 0 1120])
title('St. George')
end
function dSdt = g(t,S)
alpha=0.5;
n=0.5;
s=1/5.1;
g_I=1/7;
g_A=1/7;
g_H=1/14;
p=0.025;
d=0.015;
lambda=20;
r=0.0003;
omega=0.5;
epsilon=0.5;
dSdt = [-f(t)*(S(3)+n*S(4))*S(1)-f(t)*r*S(8)*S(1)
f(t)*(S(3)+n*S(4))*S(1)-s*S(2)
s*alpha*S(2)-p*S(3)-g_I*S(3)
s*(1-alpha)*S(2)-g_A*S(4)
p*S(3)-d*S(5)-g_H*S(5)
g_I*S(3)+g_A*S(4)+g_H*S(5)
d*S(5)
lambda*epsilon*(S(3)+n*S(4))-omega*S(8)];
end
function beta = f(t)
if (t <= 200)
beta = (78-tempStGeorge(t+1))*(0.006)+0.18;
end
end

답변 (1개)

Star Strider
Star Strider 2020년 12월 14일
I cannopt run your code.
I suspect most of ‘S’ are NaN.
Try this:
NaNs = sum(isnan(S));
I suspect they will all be equal to numel(t)-1.
Since NaN values are 0/0 or Inf/Inf, you then have to find out where the problem is.

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by