-
Notifications
You must be signed in to change notification settings - Fork 6
/
read_positions_on_annotation_v2.m
69 lines (58 loc) · 1.85 KB
/
read_positions_on_annotation_v2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function [iElectrode xyz] = read_positions_on_annotation_v2(varargin)
% READ_POSITIONS_ON_ANNOTATION_V2 loads this Carto3 position file.
% Usage:
% [iElectrode xyz] = read_positions_on_annotation_v2(filename)
% Where:
% iElectrode is a vector of electrode numbers
% xyz is an array of xyz positions
% Author: Nick Linton (2013) (Copyright)
% SPDX-License-Identifier: Apache-2.0
%
% Modifications -
% Info on Code Testing:
% ---------------------
% test code
% ---------------------
% ---------------------------------------------------------------
% code
% ---------------------------------------------------------------
filename = varargin{1};
if isempty(strfind(filename, 'OnAnnotation'))
error('READ_POSITIONS_ON_ANNOTATION_V2: filename must be an "OnAnnotation" file.')
end
fid = fopen(filename, 'r');
if fid == (-1)
error(['READ_POSITIONS_ON_ANNOTATION_V2: Could not read the file: "' filename '"']);
end
try
line1 = fgetl(fid);
line2 = fgetl(fid);
vData = fread(fid,'*char')';
fclose(fid);
catch err
fclose(fid);
rethrow(err)
end
%line 1
spaces = isspace(line1);
line1(spaces) = [];
line1 = lower(line1);
matchA = strfind(line1, 'eleclectrode_positions_2.0');
matchB = strfind(line1, 'sensor_positions_2.0');
if isempty(matchA) && isempty(matchB)
warning('READ_POSITIONS_ON_ANNOTATION_V2: The version number in the txt file is unexpected.') %#ok<*WNTAG>
end
%line 2
spaces = isspace(line2);
line2(spaces) = [];
line2 = lower(line2);
matchA = strfind(line2, 'electrode#timexyz');
matchB = strfind(line2, 'sensor#timexyz');
if isempty(matchA) && isempty(matchB)
warning('READ_POSITIONS_ON_ANNOTATION_V2: Unexpected column titles.') %#ok<*WNTAG>
end
% the rest is the data
xyz = sscanf(vData, '%f');
xyz = reshape(xyz, 5, numel(xyz)/5)';
iElectrode = xyz(:,1);
xyz = xyz(:,3:5);