prepare_ImaGIN_Electrodes.m
2.73 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function prepare_ImaGIN_Electrodes(source, polarity, FileIn, implantationFile, FileOut, FileTxtOut)
%Add electrode position
%source : 'classic' (a file with the electrodes names and another one with
%the MNI positions), implantationFile is the source directory of the 2
%files
% or 'intranat' (a file -implantationFile- with electrodes names, position, atlas,...)
[Root,file,~] = fileparts(FileIn);
clear S
S.Fname = fullfile(Root,[spm_str_manip(file,'r') '.mat']);
if strcmp(polarity,'monopolar')
if strcmp(source,'classic')
S.filenamePos = fullfile(implantationFile,'Electrodes_Pos_MNI.txt');
S.filenameName = fullfile(implantationFile,'Electrodes_Name.txt');
elseif strcmp(source, 'intranat')
S.filenameName = implantationFile;
end
else
error('No other polarity option is implemented here!')
end
% %for files generated with Intranat
% if strcmp(source, 'intranat')
% data=extractIntranatFile(implantationFile);
% for i1=1:size(data,2)
% for i2=1:size(data{i1},1)
% if strcmp(data{i1}{i2},'MNI')
% indi=i1;
% indj=i2;
% end
% end
% end
% positiontmp = data{indi};
% nametmp = data{1};
% Position = [];
% Name = cell(1,1);
% if strcmp(polarity,'monopolar')
% for i=(indj+1):length(nametmp)
% if isempty(strfind(nametmp{i},'-'))
%
% iLastLetter = find(~ismember(nametmp{i}, '0123456789'), 1, 'last');
% if isempty(iLastLetter)
% iLastLetter = 0;
% end
%
% if iLastLetter > 0
% name = [lower(nametmp{i}(1:iLastLetter)) nametmp{i}(iLastLetter+1:end)];
% Name{1} = cat(1,Name{1},{name});
% Position = cat(1,Position,str2num(positiontmp{i}));
% end
% end
% end
% else
% if strcmp(polarity, 'bipolar')
% % TODO: Throw an exception here, don't execute anything!!!
% error('Bipolar option not implemented')
% end
% end
% S.Position = Position;
% S.Name = Name;
% end
%
S.FileTxtOut = FileTxtOut;
S.FileOut = FileOut;
fprintf('prepare_ImaGIN_Electrodes: S.FileTxtOut: %s \n', S.FileTxtOut)
fprintf('prepare_ImaGIN_Electrodes: S.FileOut: %s \n', S.FileOut)
ImaGIN_Electrode(S);
set_final_status('OK')
close all
end
% % It gets the CSV file, and reads its content to Matlab structure 'data'
% function data = extractIntranatFile(filename)
% delimiter = '\t';
% formatSpec = '%s%s%s%s%s%s%s%s%s%s%s%s%s%s%[^\n\r]';
%
% fileID = fopen(filename,'r');
% data = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'ReturnOnError', false);
% fclose(fileID);
% end