% What this script does: % 1. Sets all baselines to the last 30 sec of the original baselines coded as ones ('1') % 2. Removes some conditions we are not interested in (markers between 111 and 139, stress test) % 3. Removes the baseline before the stress test % 4. Removes the final baseline % 5. Re-numbers the baselines before the films originally numbered as '1' according to the film number it preceeds

clear all; % Clear all variables in the workspace

batch=textread('Batch41.m','%s'); % Read the batch file with all EDFs

status=mkdir('baselines_30s'); % Create a new folder for modified timing files

for i=1:length(batch) % Repeat for all timing files corresponding to EDFs in the batch

  edfname=batch{i,:}; % Full pathname of the current EDF file
  [PATH,NAME,EXT] = fileparts(edfname); % Split up the pathname to get the filename and extension
  eval(NAME); % Evaluate the timing file 'NAME.m' to create the variable T in the workspace
  ind=T(:,1)==1; % Find indices of all baselines (coded as '1' in the original timing files)
  T2=T; % Create the resulting timing variable
  T2(ind,:)=[T(ind,1) T(ind,3)-30 T(ind,3) 30*ones(sum(ind),1)]; % Set all baselines to the last 30 sec of the original baselines
  stress_ind=T(:,1)>=111 & T(:,1)<=139; % Find the stress test condition (markers between 111 and 139)
  if ~isempty(stress_ind) % If anything was found ...
      stress_baseline=find(stress_ind,1,'first')-1; % ... find also the baseline before the stress test ...
      stress_ind(stress_baseline)=[]; % ... remove it, too. At first in the index of all normal baselines to make it shorter
      T2(stress_baseline,:)=[]; % Then remove the stress baseline itself
      T2(stress_ind,:)=[]; % Then remove all stress conditions
  T2(end,:)=[]; % Remove the final baseline
  % Recode the baselines ...
  for j=1:size(T2,1)-1
      if T2(j,1)==1
          T2(j,1)=T2(j+1,1)+300; % ... via assigning them the respective film number plus 300
  % Open a file for saving the resulting timing files
  fid = fopen(['.\baselines_30s\' NAME '.m'], 'w');
  fprintf(fid,'%s\r\n','T = [...'); % Print the first line of the timing file
  for j=1:size(T2,1)-1 % Print all lines except the first and the last one
      fprintf(fid, '%d\t%6.4f\t%6.4f\t%6.4f%s\r\n', T2(j,1), T2(j,2), T2(j,3), T2(j,4), ';...');
  % Print the last line
  fprintf(fid, '%d\t%6.4f\t%6.4f\t%6.4f%s\r\n', T2(end,1), T2(end,2), T2(end,3), T2(end,4), '];');
  fclose(fid); % Close file


script_1.txt · Last modified: 2013/05/07 19:20 by admin
You are here: homescript_1