|
1 | 1 | function [ processed_data ] = parse_data(fn, animal_id, rec_time, centre_x, centre_y) |
2 | 2 | %PARSE_DATA gets the data of interest from file |
3 | 3 |
|
4 | | - %Read the csv file |
5 | | - [data, header_idx] = read_ethovision(fn,rec_time, centre_x, centre_y); |
6 | | - |
| 4 | + %Read the csv or xlsx file |
| 5 | + [~, ~, ext] = fileparts(fn); |
| 6 | + if isequal(ext,'.CSV') || isequal(ext,'.csv') |
| 7 | + [data, header_idx] = read_ethovision(fn, rec_time, centre_x, centre_y); |
| 8 | + elseif isequal(ext,'.XLSX') || isequal(ext,'.xlsx') |
| 9 | + [data, header_idx] = read_ethovision_xlsx(fn, rec_time, centre_x, centre_y); |
| 10 | + end |
| 11 | + |
7 | 12 | %Initialize |
8 | 13 | id = ''; |
9 | 14 | skipped_file = ''; |
|
12 | 17 | y = {}; |
13 | 18 | damaged_file = 0; |
14 | 19 | pts = []; |
| 20 | + flag = ''; |
15 | 21 |
|
16 | 22 | %First find id |
17 | 23 | i = 1; |
18 | 24 | while i <= size(data,1) |
19 | 25 | if isequal(data{i,1},animal_id) |
20 | | - id = sscanf(data{i,2}, '%d'); |
21 | | - elseif ~isempty(str2num(data{i,1})) |
| 26 | + if isnumeric(data{i,2}) |
| 27 | + id = data{i,2}; |
| 28 | + else |
| 29 | + id = sscanf(data{i,2}, '%d'); |
| 30 | + end |
| 31 | + end |
| 32 | + try |
| 33 | + flag = str2num(data{i,1}); |
| 34 | + catch |
| 35 | + flag = data{i,1}; |
| 36 | + end |
| 37 | + if ~isempty(flag) |
22 | 38 | %if we are here then we should have the id |
23 | 39 | if isempty(id) |
24 | 40 | %indicate which file was skipped |
|
71 | 87 | else |
72 | 88 | for i = 1:length(time) |
73 | 89 | % extract time, X and Y coordinates |
74 | | - T = sscanf(time{i, 1}, '%f'); |
75 | | - X = sscanf(x{i, 1}, '%f'); |
76 | | - Y = sscanf(y{i, 1}, '%f'); |
| 90 | + if isnumeric(time{i, 1}) |
| 91 | + T = time{i, 1}; |
| 92 | + else |
| 93 | + T = sscanf(time{i, 1}, '%f'); |
| 94 | + end |
| 95 | + if isnumeric(x{i, 1}) |
| 96 | + X = x{i, 1}; |
| 97 | + else |
| 98 | + X = sscanf(x{i, 1}, '%f'); |
| 99 | + end |
| 100 | + if isnumeric(y{i, 1}) |
| 101 | + Y = y{i, 1}; |
| 102 | + else |
| 103 | + Y = sscanf(y{i, 1}, '%f'); |
| 104 | + end |
77 | 105 | % discard missing samples |
78 | 106 | if ~isempty(T) && ~isempty(X) && ~isempty(Y) |
79 | 107 | pts = [pts; T X Y]; |
|
0 commit comments