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: QrefineRB.m
    path of file: ./repos/ameshref/refinement
    
    the code of the file until where you have to start completion: function [coordinates,newElements,varargout] ...
    = QrefineRB(coordinates,elements,varargin)

%QrefineRB: local refinement of quadrilateral mesh by red-blue refinement, 
%          where marked elements are refined by bisecting all edges 
%          of the element
%
%Usage:
%
% [coordinates,elements4,dirichlet,neumann] ...
%    = QrefineRB(coordinates,elements4,dirichlet,neumann,marked)
% or

    
function [coordinates,newElements,varargout] ...
    = QrefineRB(coordinates,elements,varargin)

%QrefineRB: local refinement of quadrilateral mesh by red-blue refinement, 
%          where marked elements are refined by bisecting all edges 
%          of the element
%
%Usage:
%
% [coordinates,elements4,dirichlet,neumann] ...
%    = QrefineRB(coordinates,elements4,dirichlet,neumann,marked)
% or
%
% [coordinates,elements4] ...
%    = QrefineRB(coordinates,elements4,marked)
%
%Comments:
%
%    QrefineRB expects as input a mesh described by the 
%    fields coordinates, elements4, dirichlet (optional) and neumann 
%    (optional). The vector marked contains the indices of elements which
%    are refined by refining all edges of the element.
%    Further elements will be refined by a red-blue refinement to obtain
%    a regular triangulation. To ensure shape regularity of the mesh,
%    blue elements are coarsened before further refined.
% 
%    The function returns the refined mesh in terms of the same data as
%    for the input.
%
%Remark:
%
%    This program is a supplement to the paper 
%    >> Adaptive Mesh Refinement in 2D - An Efficient Implementation in Matlab <<
%    by S. Funken, and A. Schmidt. The reader should 
%    consult that paper for more information.   
%
%Authors:
% 
%    S. Funken, A. Schmidt  20-08-18

persistent nB;
nE = size(elements,1);
markedElements = varargin{end