% Written by Thibo Billiet - KU Leuven % e-mail: thibo.billiet@uzleuven.be function g_mrtrix=g_edti_to_mrtrix(file) load(file,'g','bval','NrB0'); n_gradients=size(g,1); %add the gradient value for each gradient tmp=[g, bval*ones(n_gradients,1)]; % add rows of zeroes for each b0 image zeroes=zeros(NrB0,4); tmp=[zeroes;tmp]; g_mrtrix=tmp; % switch X and Y column g_mrtrix(:,1)=tmp(:,2); g_mrtrix(:,2)=tmp(:,1); % change the sign Z column g_mrtrix(:,3) = -g_mrtrix(:,3); [pathstr, name, ext] = fileparts(file); FID=fopen([pathstr filesep name '_g_mrtrix.txt'],'w'); fprintf(FID,'%d %d %d %d\n',g_mrtrix'); fclose(FID);