-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_wrist_task_raw_logs.m
54 lines (46 loc) · 1.77 KB
/
load_wrist_task_raw_logs.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
49
50
51
52
53
54
function T = load_wrist_task_raw_logs(filename)
%LOAD_WRIST_TASK_RAW_LOGS Import data from a text file.
%
% Syntax:
% T = io.load_wrist_task_raw_logs(FILENAME)
%
% Description:
% Reads data from text file FILENAME for the default selection.
% Returns the data as a table.
%
% Example:
% T = importfile("R:\NMLShare\raw_data\primate\Spencer\Behavior\Spencer_2021_10_17_Trial-Data_10-29-12.log", [1, Inf]);
%
% See also: Contents, READTABLE, DELIMITEDTEXTIMPORTOPTIONS,
% io.load_wrist_task_trial_logs
% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 5);
% Specify range and delimiter
opts.DataLines = [1, inf];
opts.Delimiter = " ";
% Specify column names and types
opts.VariableNames = ["Date", "Time", "log_type", "var_category", "raw"];
opts.VariableTypes = ["string", "string", "string", "string", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts.ConsecutiveDelimitersRule = "join";
opts.LeadingDelimitersRule = "ignore";
% Specify variable properties
opts = setvaropts(opts, ["Date", "Time", "var_category", "log_type", "raw"], "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["Date", "Time", "var_category", "log_type", "raw"], "EmptyFieldRule", "auto");
% Import the data
T = readtable(filename, opts);
% % % --> Added by MM <-- % % %
% Remove brackets.
T.var_category = strrep(T.var_category, "[", "");
T.var_category = strrep(T.var_category, "]", "");
T.ts = datetime(strcat(T.Date, " ", T.Time), ...
'TimeZone','America/New_York', ...
'InputFormat', 'yyyy-MM-dd HH:mm:ss,SSS', ...
'Format', 'yyyy-MM-dd HH:mm:ss.SSS');
T.Date = [];
T.Time = [];
T = movevars(T, 'ts', 'Before', 1);
T = table2timetable(T, 'RowTimes', 'ts');
end