Skip to content

Instantly share code, notes, and snippets.

@divyanganar
Last active April 25, 2022 04:21
Show Gist options
  • Save divyanganar/e02e38aa1db1d39fbb8b6a017bb2bbd5 to your computer and use it in GitHub Desktop.
Save divyanganar/e02e38aa1db1d39fbb8b6a017bb2bbd5 to your computer and use it in GitHub Desktop.
MATLAB function to calculate framewise displacement from 6 motion parameters
function [mat, fwd_percent] = fwd(subj_numb, filename, exit_file, csv_file, run)
mat = textread(filename);
radius = 50; %mm
ts = mat;
temp = mat(:,4:6)*180/pi; %convert to degrees
temp = (2*radius*pi/360)*temp;
ts(:,4:6) = temp;
dts = diff(ts);
fwd = sum(abs(dts),2);
a = 0.0;
fwd = [a;fwd];
mat = [mat fwd];
fwd_1 = fwd>0.2;
fwd_ex = fwd(fwd_1);
fwd_percent = (size(fwd_ex)/size(fwd))*100;
fwd_percent = round(fwd_percent);
fid = fopen(exit_file,'a+');
fprintf(fid,'%s has %d percent volumes higher than 0.2 in %s\n',subj_numb,fwd_percent,run);
fclose(fid);
mat = array2table(mat);
writetable(mat,csv_file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment