-
Notifications
You must be signed in to change notification settings - Fork 0
/
importfile2.m
48 lines (39 loc) · 2.61 KB
/
importfile2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function statesdaily4pmet = importfile2(filename, dataLines)
%IMPORTFILE Import data from a text file
% STATESDAILY4PMET = IMPORTFILE(FILENAME) reads data from text file
% FILENAME for the default selection. Returns the data as a table.
%
% STATESDAILY4PMET = IMPORTFILE(FILE, DATALINES) reads data for the
% specified row interval(s) of text file FILENAME. Specify DATALINES as
% a positive scalar integer or a N-by-2 array of positive scalar
% integers for dis-contiguous row intervals.
%
% Example:
% statesdaily4pmet = importfile("/Users/isaac_weintraub_admin/Projects/COVID19/covid-tracking-data/data/states_daily_4pm_et.csv", [2, Inf]);
%
% See also READTABLE.
%
% Auto-generated by MATLAB on 07-Jul-2020 12:12:50
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [2, Inf];
end
%% Setup the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 39);
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["date", "state", "positive", "negative", "pending", "hospitalizedCurrently", "hospitalizedCumulative", "inIcuCurrently", "inIcuCumulative", "onVentilatorCurrently", "onVentilatorCumulative", "recovered", "dataQualityGrade", "lastUpdateEt", "dateModified", "checkTimeEt", "death", "hospitalized", "dateChecked", "totalTestsViral", "positiveTestsViral", "negativeTestsViral", "positiveCasesViral", "fips", "positiveIncrease", "negativeIncrease", "total", "totalTestResults", "totalTestResultsIncrease", "posNeg", "deathIncrease", "hospitalizedIncrease", "hash", "commercialScore", "negativeRegularScore", "negativeScore", "positiveScore", "score", "grade"];
opts.VariableTypes = ["double", "categorical", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "categorical", "datetime", "categorical", "categorical", "double", "double", "categorical", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "string", "double", "double", "double", "double", "double", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, ["hash", "grade"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["state", "dataQualityGrade", "dateModified", "checkTimeEt", "dateChecked", "hash", "grade"], "EmptyFieldRule", "auto");
opts = setvaropts(opts, "lastUpdateEt", "InputFormat", "MM/dd/yyyy HH:mm");
% Import the data
statesdaily4pmet = readtable(filename, opts);
end