%% This function computes framewise displacement from an rp file function [FD,BinMat,PScrub,MOT] = ComputeFD(PathToSubjFolder,SOI,MotThresh,Ses_prefix) cd(PathToSubjFolder); idx = 1; for s = 1:length(SOI) cd(SOI{s}); tmp_ses = dir([Ses_prefix,'*']); for ses = 1:3 try cd(tmp_ses(ses).name); % Gets the motion information (two motion file names). We want to % get the data from the first one tmp_mot = cellstr(spm_select('List',pwd,['^' 'rp_f' '.*\.' 'txt' '$'])); % Mot is a 340 x 6 matrix containing the info the the session % considered for all 6 motion parameters Mot = textread(tmp_mot{1}); Mot = Mot(:,1:6); % Converts last columns into mm Mot(:,4:6) = Mot(:,4:6) * 50; % Gets the differential DMot = diff(Mot,1); DMot = [zeros(1,6);DMot]; % framewise displacement for the considered sessions FD{idx} = sum(abs(DMot),2); MOT{idx} = Mot; cd('..'); idx = idx + 1; catch disp('Could not find third session...'); FD{idx} = NaN; MOT{idx} = NaN; idx = idx + 1; end end cd('..'); end for i = 1:length(FD) if ~isnan(FD{i}) PScrub(i) = 100*(sum((FD{i} > MotThresh)))/(length(FD{i})); else PScrub(i) = NaN; end end % Summarizing matrix for frames to scrub BinMat = 0; cd('..'); end