Phase differences between DFT and FFT (in MatLab)
you should replace the line

n = (1:length(data))/length(data); % Calculate the n/N factor


with the line

n = (0:length(data)-1)/length(data); % Calculate the n/N factor


Note that in the standard DFT (and FFT), the indices for both $x[n]$, $X[k]$ range in $0 \leq n,k \leq N-1$.