File Exchange

image thumbnail

COVID-19 Modeling

version 3.6.3 (2.73 MB) by Joshua McGee
This model was created based off of fitVirus. This is a data-driven model that obtains up to date data and predicts the spread of COVID-19.


Updated 03 May 2020

View License

Created to track the simulate the spread of Coronavirus (COVID-19). Case data is obtained over the web and fitted to a logistic model to predict epidemic spread over time.

To operate load the folder containing the script COVID19Modelingv2 and type the following code in the command prompt: COVID19Modelingv2("country").
example: COVID19Modelingv2("US"). Multiple countries can be analyzed at the same time by placing them in a list: COVID19Modelingv2("US","Italy").

The model was created by Milan Batista (fitVirus). The model is a data-driven model that fits epidemic data to a logistic curve. The goal of the model is to make local predictions about the viral spread and epidemic duration. The model can be used to provide accurate approximations in certain situations. "The regression convergence may fail for a pure initial guess or small data set. Therefore the method does not apply to the early stages of an epidemic. Also, results are useless if the regression statistic does not meet minimum criteria, say R^2 > 0.8, p-value < 0.05." (Milan Batista)

DISCLAIMER: Model will fail in certain situations. A rigorous statistical analysis should be performed on all results. The model fails when additional epidemic stages (not described by logistic function) are encountered. Use at your own discretion.

See for more info:

Data is stored online and is provided via JHU CSSE from various sources including:
"The World Health Organization (WHO), Pneumonia. 2020, BNO News,
National Health Commission of the People? Republic of China (NHC),
China CDC (CCDC), Hong Kong Department of Health, Macau Government, Taiwan CDC, US CDC, Government of Canada, Australia Government Department of Health, European Centre for Disease Prevention and Control (ECDC) and Ministry of Health Singapore (MOH)"

On the figure, the epidemic rate is plotted with a blue line (cases/day). Blue dots are the actual infection rate (cases/day). Region colors separate epidemic transition phases:
red - fast growth phase
yellow - transition to steady-state phase
green - ending phase

Cite As

Joshua McGee (2020). COVID-19 Modeling (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (34)

Error using COVID19Modelingv2 (line 94)
Row index exceeds table dimensions.

how could this be fixed ?

dai yang

Al K

Sorry Error
Error using COVID19Modelingv2 (line 47)
Table variable names must be character vectors.

Kais Zaman

Error using COVID19Modelingv2 (line 47)
Table variable names must be character vectors.

Joshua McGee

Hi Eugene,
A 3 parameter logistic model is fitted from the data.
This is of the form: A/(1+B*exp(-C*t))

The program works beautifully. I have a routine for fitting the continuous form of the logistic, but I'm coming up with slightly different (lower) values of K. I need to track down how you are fitting a 3-parameter model, when the logistic is based on just r & K.

Error using livemapcovid19 (line 46)
Table variable names must be character vectors.

Joshua McGee



requires optimization toolbox that is not currently stated in submission.

Ted Hanes

Here is a source for state-level data:

Joshua McGee

The original data still exists but it is no longer being updated.

Joshua McGee

Hi Kirtis,
The original data set was discontinued by the source. See "".
Unfortunately, there is nothing I can do about this. I did not originally intend for this model to provide state-level modelling. I'll let you know if I find a new data source.

I don't see the United States broken out in the input file on the web path that feeds the result variable. A prior version had a source path for result that had data for US and each state broken out. That was needed for assisting in regional planning.
when I run this version I get the following error -> Too many output arguments.
Can we get those source data by state restored to the excel file in the input path? And a confirmation that the other are seeing the same error that I am?

Excellent work. Runs great. Thanks for the hard work.

Joshua McGee

Fixed all compatibility issues (hopefully)

Ralf Elsas

Joshua McGee

Hi Suksan. This is a compatibility issue that I am still trying to resolve. The code runs fine on my version (2019b).

excellent work, but when I run the code it gives me this error:
Unrecognized property 'PreserveVariableNames' for class
Error in fitVirusCV19v3 (line 132)
opts.PreserveVariableNames = true;

Joshua McGee

Hi Morgan,

I'm running 2019b with no issues. There must be a compatibility issue with the importing of the data. I'll work on a more robust method.


Receiving this error, using version R2020a.

Error using COVID19Modelingv2 (line 62)
Duplicate table variable name: 'NaN'.

Joshua McGee

Hi Tsotne. I've heard from other users that this is a compatibility issue. The easiest fix would be to upgrade your MATLAB to 2019b or newer.

"Starting in R2019b, variable names and row names can include any characters, including spaces and non-ASCII characters. Also, they can start with any characters, not just letters. Variable and row names do not have to be valid MATLAB identifiers (as determined by the isvarname function). To preserve these variable names and row names, set PreserveVariableNames to true."

Thank you very much for your work. I have this particular error

Unrecognized property 'PreserveVariableNames' for class ''.

Error in COVID19Modelingv2 (line 24)
opts.PreserveVariableNames = true;

What should I do?

Hey, everybody, I tried to see which part of the document is empty. I can't find it, could you help me? I keep getting the message:
Error using (line 73)
DataLine must be a positive integer.

Error in COVID19Modelingv2 (line 23)
opts.DataLine = [2,inf];

I'm using R2017b


Joshua McGee

Thanks Kirtis. I’ll try and reach out to the people that maintain the dataset. It’s very dynamic so hopefully it’ll be updated soon.

Hey everyone. This was working fine but it has stopped. Be advised that the update to the deaths file that this model depends upon failed for column 3/21. If someone has access to fix that column this will start working gain. Otherwise the workaround follows. Pull the files to your local folder and use readtable instead of

If you fix the empty data in 3/21 for deaths.csv on your local folder and us the following line things will work gain until the online files are fixed.
%Use local data because online data seems broke at the moment
deathresult = readtable('time_series_2019-ncov-Deaths.csv');

ilPlus30 I got the same error. I believe it is some version compatibility problems. I was able to run the script for my country by making some changes to the code. For that specific problem, the solution was to change the code opts.DataLines = [2,inf]; to opts.DataLine = [2,inf]; because there is no DataLines variable in opts.

Joshua McGee

Hi iiPlus30. This is a most likely a compatibility issue with your version of MATLAB. Other users and I have not encountered this error. What version are you running?


No public property DataLines exists for class

Error in COVID19Modelingv2 (line 23)
opts.DataLines = [2,inf];

Joshua McGee

Is this working correctly for everyone?



updated 5/2


updated 4/30


updated 4/22


updated 4/18


updated 4/17


updated and added notes 4/15


updated with link to in-depth description


updated 4/15


updated image


-updated graph style


updated 4/13


-updated 4/13


updated 4/11


-updated 4/10


update 4/9


-updated 4/8


-updated 4/6


-updated 4/5


-updated 4/5


-updated data




-updated 4/1


-fixed graphs on the example tab


updated 3/31


-fixed plots in example tab




-added more examples


-updated examples


-made script executable as a function
-added examples


-bug fixes and improvements


-optimization notes


-bug fix






-bug fixes and compatibility








-attempted to fix variable name compatibility issues




-compatibility fixes


-fixed all compatibility issues


-bug fixes


-fixed predict() function courtesy of Milan Batista


-updated to reflect changes in database


-compatibility note


-updated compatibility


-added graph to visualize stability of total infected estimate (courtesy of Milan Batista)


-ability to run multiple country simulations simultaneously


-version #




MATLAB Release Compatibility
Created with R2019b
Compatible with R2019b to any release
Platform Compatibility
Windows macOS Linux

Inspired by: fitVirus

Inspired: Coronavirus Tracker - Country Modeling