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: generate_coil.m
    path of file: ./repos/MATBOX_Microstructure_analysis_toolbox/src/Microstructure_generation
    
    the code of the file until where you have to start completion: function [microstructure] = generate_coil(coil_diameter,coil_thickness,coil_length,rotation_speed,additional_distance_throughplane,additional_distance_inplane,coil_is_background)


%% SET DISTANCE AND DOMAIN SIZE
coil_radius = coil_diameter/2;
additional_distance_throughplane=round(additional_distance_throughplane*coil_length);
additional_distance_inplane=round(additional_distance_inplane*coil_diameter);

% Domain size
n_1 = round(coil_length + additional_distance_throughplane);

    
function [microstructure] = generate_coil(coil_diameter,coil_thickness,coil_length,rotation_speed,additional_distance_throughplane,additional_distance_inplane,coil_is_background)


%% SET DISTANCE AND DOMAIN SIZE
coil_radius = coil_diameter/2;
additional_distance_throughplane=round(additional_distance_throughplane*coil_length);
additional_distance_inplane=round(additional_distance_inplane*coil_diameter);

% Domain size
n_1 = round(coil_length + additional_distance_throughplane);
n_2 = round(coil_diameter + 2*additional_distance_inplane);
n_3=n_2;

% Domain size
Domain_size=[n_1 n_2 n_3];

%% ASSIGN VOXELS
% Initialise microstructure
microstructure = zeros(Domain_size(1),Domain_size(2),Domain_size(3));
% Coil center in the plane
a=(n_2/2);
b=(n_3/2);
theta=0;
incrementpervoxel_coil_rotation = rotation_speed * 2*pi/coil_diameter;
for x=Domain_size(1)-additional_distance_throughplane:-1:1
    x_ = max(a + coil_radius*cos(theta),0.51);
    y_ = max(b + coil_radius*sin(theta),0.51);    
    microstructure(round(x),round(x_),round(y_))=1;
    theta=theta+incrementpervoxel_coil_rotation;
    if theta>=2*pi
        theta=0;
    end