You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: test_nfft2d_nufft.m
    path of file: ./repos/nfft/matlab/nfft
    
    the code of the file until where you have to start completion: 
% Copyright (c) 2002, 2019 Jens Keiner, Stefan Kunis, Daniel Potts
%
% This program is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free Softw
    
function "nufft" is only supperoted by Matlab 2020a or newer.')
  return
end

M=16000; % number of nodes
N1=128; % number of Fourier coefficients in first direction
N2=128; % number of Fourier coefficients in second direction
N=[N1;N2];

x=rand(M,2)-0.5; %nodes

% Initialisation
tic
plan=nfft(2,N,M); % create plan of class type nfft
%n=2^(ceil(log(max(N))/log(2))+1);
%plan=nfft(2,N,M,n,n,8,bitor(PRE_PHI_HUT,bitor(PRE_PSI,NFFT_OMP_BLOCKWISE_ADJOINT)),FFTW_MEASURE); % use of nfft_init_guru

plan.x=x; % set nodes in plan and perform precomputations
fprintf('Time NFFT pre    = %g sec\n',toc)

% NFFT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

fhat=rand(N1,N2); % Fourier coefficients
fhatv=fhat(:);

% Compute samples with NFFT
plan.fhat=fhatv; % set Fourier coefficients
tic
nfft_trafo(plan); % compute nonequispaced Fourier transform
fprintf('Time NFFT trafo  = %g sec\n',toc)
f1=plan.f; % get samples

% Compute samples direct
k1=-N1/2:N1/2-1;
k2=-N2/2:N2/2-1;
[K1,K2]=ndgrid(k1,k2);
k=[K1(:) K2(:)];
clear K1 K2;
f2=zeros(M,1);
for j=1:M
	f2(j)=sum( fhatv.*exp(-2*pi*1i*(k*x(j,:).')) );
end