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: zigzag6dof.m
    path of file: ./repos/MSS/GNC
    
    the code of the file until where you have to start completion: function zigzag6dof(vehicle,x,ui,t_final,t_rudderexecute,h,maneuver)
% zigzag6dof(vehicle,x,ui,t_final,t_rudderexecute,h,maneuver) performs the 
% zigzag maneuver for 6-DOF models, see ExZigZag.m
%
% Inputs:
% 'vehicle':       vehicle model. Compatible with the Remmus 100 AUV located
%                  under .../VESSELS
% x:               initial state vector for vehicle model
% ui:              [delta,:] where delta=0 and the other values are nonzero if any
% t_final:         final simulation time
% t_rudderexecute: time for which control input is activated
% h:               sampling time
% maneuver         [rudder angle, heading angle]. Default 20-20 deg, i.e. 
%                  maneuver = [20, 20] rudder is changed to maneuver(1) when 
%                  the heading angle is larger than maneuver(2)
%
% Author:          Thor I. Fossen
% Date:            18 Nov 2023

    
function zigzag6dof(vehicle,x,ui,t_final,t_rudderexecute,h,maneuver)
% zigzag6dof(vehicle,x,ui,t_final,t_rudderexecute,h,maneuver) performs the 
% zigzag maneuver for 6-DOF models, see ExZigZag.m
%
% Inputs:
% 'vehicle':       vehicle model. Compatible with the Remmus 100 AUV located
%                  under .../VESSELS
% x:               initial state vector for vehicle model
% ui:              [delta,:] where delta=0 and the other values are nonzero if any
% t_final:         final simulation time
% t_rudderexecute: time for which control input is activated
% h:               sampling time
% maneuver         [rudder angle, heading angle]. Default 20-20 deg, i.e. 
%                  maneuver = [20, 20] rudder is changed to maneuver(1) when 
%                  the heading angle is larger than maneuver(2)
%
% Author:          Thor I. Fossen
% Date:            18 Nov 2023
% Revisions: 

if nargin>7 || nargin < 6, error('number of inputs must be 6 or 7'); end
if t_final < t_rudderexecute
    error('t_final must be larger than t_rudderexecute'); 
end
if nargin == 6, maneuver = [20,20]; end

N = round(t_final/h);               % number of samples
xout = zeros(N+1,15);               % memory allocation

disp('Simulating...')

u_vehicle = ui;

for i=1:N+1
    time = (i-1)*h;
    
    psi = rad2deg( x(12) );
    r = x(6);
    
    if round(time) == t_rudderexecute 
        u_vehicle(1) = deg2rad( maneuver(1) ); 
    end