Authored by Olivier David

Improve Bipolar Montage input

@@ -30,20 +30,25 @@ catch @@ -30,20 +30,25 @@ catch
30 end 30 end
31 31
32 try 32 try
33 - SaveChannels = S.Save; 33 + Bipole=S.Bipole;
34 catch 34 catch
35 - SaveChannels = 0; 35 + Bipole = [];
36 end 36 end
37 37
38 try 38 try
39 - bipole = load(S.Bipole);  
40 - 39 + SaveChannels = S.Save;
41 catch 40 catch
42 - bipole = []; 41 + SaveChannels = 0;
43 end 42 end
44 43
45 44
  45 +
46 for i0=1:size(Filename,1) 46 for i0=1:size(Filename,1)
  47 + try
  48 + bipole = load(Bipole);
  49 + catch
  50 + bipole = Bipole;
  51 + end
47 T=deblank(Filename(i0,:)); 52 T=deblank(Filename(i0,:));
48 D=spm_eeg_load(T); 53 D=spm_eeg_load(T);
49 54
@@ -109,9 +109,9 @@ end @@ -109,9 +109,9 @@ end
109 109
110 110
111 % Set positions 111 % Set positions
112 -chNotFound = {};  
113 -chMatchLog = {};  
114 for i0 = 1:size(t,1) 112 for i0 = 1:size(t,1)
  113 + chNotFound = {};
  114 + chMatchLog = {};
115 T = deblank(t(i0,:)); 115 T = deblank(t(i0,:));
116 % Clone file if requested in input 116 % Clone file if requested in input
117 if (nargin >= 1) && isfield(S, 'FileOut') && ~isempty(S.FileOut) 117 if (nargin >= 1) && isfield(S, 'FileOut') && ~isempty(S.FileOut)
@@ -136,6 +136,7 @@ for i0 = 1:size(t,1) @@ -136,6 +136,7 @@ for i0 = 1:size(t,1)
136 sensLtmp(ismember(double(sensLtmp),[',' ';' '-'])) =''; 136 sensLtmp(ismember(double(sensLtmp),[',' ';' '-'])) ='';
137 Sensors.label{i1} = sensLtmp; 137 Sensors.label{i1} = sensLtmp;
138 iChanPos = findChannel(Sensors.label{i1}, Name, 'all_upper'); 138 iChanPos = findChannel(Sensors.label{i1}, Name, 'all_upper');
  139 + iChanPos = findChannel(upper(Sensors.label{i1}), upper(Name), 'all_upper');
139 % If the channel was already found in the list before: check the best option based on the case 140 % If the channel was already found in the list before: check the best option based on the case
140 if ~isempty(iChanPos) && ~isempty(chMatchLog) 141 if ~isempty(iChanPos) && ~isempty(chMatchLog)
141 iPrevious = find(strcmp(Name{iChanPos}, chMatchLog(:,2))); 142 iPrevious = find(strcmp(Name{iChanPos}, chMatchLog(:,2)));
@@ -204,16 +205,18 @@ for i0 = 1:size(t,1) @@ -204,16 +205,18 @@ for i0 = 1:size(t,1)
204 end 205 end
205 206
206 % Match file: Correspondance between SEEG-CSV-LENA conventions 207 % Match file: Correspondance between SEEG-CSV-LENA conventions
207 - if isfield(S, 'FileTxtOut') && ~isempty(S.FileTxtOut)  
208 - try  
209 - fid = fopen(S.FileTxtOut,'w');  
210 - fprintf(fid,'SEEG,CSV\n');  
211 - for i = 1:size(chMatchLog,1)  
212 - fprintf(fid,'%s,%s\n', chMatchLog{i,1}, chMatchLog{i,2}); 208 + try
  209 + if isfield(S, 'FileTxtOut') && ~isempty(S.FileTxtOut)
  210 + try
  211 + fid = fopen(S.FileTxtOut,'w');
  212 + fprintf(fid,'SEEG,CSV\n');
  213 + for i = 1:size(chMatchLog,1)
  214 + fprintf(fid,'%s,%s\n', chMatchLog{i,1}, chMatchLog{i,2});
  215 + end
  216 + fclose(fid);
  217 + catch
  218 + disp('Log with matched channels names SEEG-CSV not saved.')
213 end 219 end
214 - fclose(fid);  
215 - catch  
216 - disp('Log with matched channels names SEEG-CSV not saved.')  
217 end 220 end
218 end 221 end
219 222
@@ -309,11 +312,19 @@ for i0 = 1:size(t,1) @@ -309,11 +312,19 @@ for i0 = 1:size(t,1)
309 SpmMat.D.trials.events(iEvt).type = noteNameNew; 312 SpmMat.D.trials.events(iEvt).type = noteNameNew;
310 end 313 end
311 end 314 end
312 - csv_struct.csv_labels = csv_all_electrodes(:,1); 315 + try
  316 + csv_struct.csv_labels = csv_all_electrodes(:,1);
  317 + catch
  318 + elec_labels = Name';
  319 + elec_labels_no_primes = strrep(elec_labels,'p','''');
  320 + csv_all_electrodes = [elec_labels elec_labels_no_primes];
  321 + csv_struct.csv_labels = csv_all_electrodes(:,1);
  322 + end
313 SpmMat.D.other = csv_struct; % Add an extra field to the .mat so we have a listing of all channel labels in the csv. 323 SpmMat.D.other = csv_struct; % Add an extra field to the .mat so we have a listing of all channel labels in the csv.
314 % Update existing .mat file 324 % Update existing .mat file
315 save(SpmFile, '-struct', 'SpmMat'); 325 save(SpmFile, '-struct', 'SpmMat');
316 save(spm_eeg_load(SpmFile)); % SPM's save to create a valid SPM object 326 save(spm_eeg_load(SpmFile)); % SPM's save to create a valid SPM object
  327 + clear csv_all_electrode csv_struct
317 end 328 end
318 329
319 end 330 end