-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportCGM.m
47 lines (39 loc) · 1.32 KB
/
importCGM.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
function [time, glycemia] = importCGM(filename, dataLines)
%IMPORTFILE Import data from a text file
% [TIME, GLYCEMIA] = IMPORTFILE(FILENAME) reads data from text file
% FILENAME for the default selection. Returns the data as column
% vectors.
%
% [TIME, GLYCEMIA] = 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:
% [time, glycemia] = importfile("/Users/marekwadinger/MATLAB-Drive/biokyb/gam/CGM_data/Dat_D01_sensor.csv", [1, Inf]);
%
% See also READTABLE.
%
% Auto-generated by MATLAB on 17-Nov-2021 09:56:24
%% Input handling
% If dataLines is not specified, define defaults
if nargin < 2
dataLines = [1, Inf];
end
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 2);
% Specify range and delimiter
opts.DataLines = dataLines;
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["time", "glycemia"];
opts.VariableTypes = ["double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Import the data
tbl = readtable(filename, opts);
%% Convert to output type
time = tbl.time;
glycemia = tbl.glycemia;
end