File Exchange

image thumbnail

COVID-19 Modeling

version 3.6.3 (2.73 MB) by JM2
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 Version History

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

JM2 (2021). COVID-19 Modeling (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (34)

Philipp Kügler

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

how could this be fixed ?

dai yang

Al K

Nafees Ahamad

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.


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

Eugene Gallagher

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.

Dzenan Smajic


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




requires optimization toolbox that is not currently stated in submission.

Ted Hanes

Here is a source for state-level data:


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


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.

Kirtis Christensen

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?

Morgan Evans

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


Fixed all compatibility issues (hopefully)

Ralf Elsas


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

Suksan Suwanarat

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;


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.


Morgan Evans

Receiving this error, using version R2020a.

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


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."

Tsotne Marghia

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?

Rolf Boelens

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



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.

Kirtis Christensen

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');

Orides Golyjeswski

Orides Golyjeswski

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.


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];


Is this working correctly for everyone?

Matlab Expert

MATLAB Release Compatibility
Created with R2019b
Compatible with R2019b and later releases
Platform Compatibility
Windows macOS Linux

Inspired by: fitVirus

Inspired: Coronavirus Tracker - Country Modeling

Community Treasure Hunt

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

Start Hunting!