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: irregnLYaw.m
    path of file: ./repos/WEC-Sim/source/functions/simulink/model
    
    the code of the file until where you have to start completion: function [Fext,relYawLast,coeffsLastMD,coeffsLastRE,coeffsLastIM] = irregnLYaw(A,w,dofGRD,dirGRD,wGRD,fEHRE,fEHIM, fEHMD, phaseRand,dw,time,direction,spread, Disp, intThresh, prevYaw, prevCoeffMD, prevCoeffRE, prevCoeffIM)
%#codegen
% Fext is the excitation force output, relYawLast is the angle of relative
% yaw at which that last interpolation was performed. If the current
% relative yaw angle - last interpolated > threshold, the interpolation is
% performed again. To interpolate every time step, let threshold=0.

% caseFlag is for debug, delete when satisfied
A1=bsxfun(@plus,w*time,pi/2);
%initialize outputs
Fext = zeros(1,6);
relYawLast=0;
coeffsLastMD=zeros(length(w),6);

    
function [Fext,relYawLast,coeffsLastMD,coeffsLastRE,coeffsLastIM] = irregnLYaw(A,w,dofGRD,dirGRD,wGRD,fEHRE,fEHIM, fEHMD, phaseRand,dw,time,direction,spread, Disp, intThresh, prevYaw, prevCoeffMD, prevCoeffRE, prevCoeffIM)
%#codegen
% Fext is the excitation force output, relYawLast is the angle of relative
% yaw at which that last interpolation was performed. If the current
% relative yaw angle - last interpolated > threshold, the interpolation is
% performed again. To interpolate every time step, let threshold=0.

% caseFlag is for debug, delete when satisfied
A1=bsxfun(@plus,w*time,pi/2);
%initialize outputs
Fext = zeros(1,6);
relYawLast=0;
coeffsLastMD=zeros(length(w),6);
coeffsLastRE=zeros(length(w),6);
coeffsLastIM=zeros(length(w),6);

for ii=1:length(direction)
    relYaw=direction(ii)-(Disp(6)*180/pi); % relative yaw angle
    phaseRandint=phaseRand(:,ii);
    WaveSpreadint=spread(ii);
    
       % compare relYaw to available direction data
        if relYaw>max(dirGRD(1,:,1)) % handle interpolation out of BEM range by wrapping other bound
            [~,idx]=min(dirGRD(1,:,1),[],2); % 
            dirGRD(:,idx,:)=dirGRD(:,idx,:)+360;
            [dirGRD,I]=sort(dirGRD,2); % grid must be in ascend