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: udmatcal.m
    path of file: ./repos/acycle/code/package/undatable/private
    
    the code of the file until where you have to start completion: function  [p95_4, p68_2, calprob, medage] = matcal(labdet, laberr, calcurve, yeartype, varargin)
% [p95_4, p68_2, calprob, medage] = matcal(labdet, laberr, calcurve, yeartype)
%
% Function for 14C age calibration using Bayesian higher posterior
% density analysis of a probability density function of calibrated age.
%
% Please see manuscript for more detailed information:
% Lougheed, B.C. & Obrochta, S.P. (2016). MatCal: Open Source Bayesian
% 14C Age Calibration in Matlab. Journal of Open Research Software. 4(1),
% p.e42. DOI: http://doi.org/10.5334/jors.130
%
% Required input parameters
% =================================
%
% labdet:    Lab 14C determination (default unit is 14C yr BP).
%
% laberr:    Lab 14C determination uncertainty (1 sigma).
%
% calcurve:  String specifying calibration curve to use, select from

    
function  [p95_4, p68_2, calprob, medage] = matcal(labdet, laberr, calcurve, yeartype, varargin)
% [p95_4, p68_2, calprob, medage] = matcal(labdet, laberr, calcurve, yeartype)
%
% Function for 14C age calibration using Bayesian higher posterior
% density analysis of a probability density function of calibrated age.
%
% Please see manuscript for more detailed information:
% Lougheed, B.C. & Obrochta, S.P. (2016). MatCal: Open Source Bayesian
% 14C Age Calibration in Matlab. Journal of Open Research Software. 4(1),
% p.e42. DOI: http://doi.org/10.5334/jors.130
%
% Required input parameters
% =================================
%
% labdet:    Lab 14C determination (default unit is 14C yr BP).
%
% laberr:    Lab 14C determination uncertainty (1 sigma).
%
% calcurve:  String specifying calibration curve to use, select from
%            the following (not case sensitive):
%            'IntCal20', 'Marine20', 'SHCal20', 'IntCal13', 'Marine13',
%			 'SHCal13, 'IntCal09', 'Marine09', 'IntCal04', 'Marine04',
%			 'SHCal04, 'IntCal98', 'Marine98'
%
% yeartype:  String specifying how to report calibrated age.
%            Choices are 'CalBP' or 'BCE/CE'. (Not case sensitive)
%
% Optional input parameters
% =================================
%
% resage:    Optional (parameter name and value). Specify reservoir
%            age in 14C yr. Reservoir age is R(t) in the case of an 
%			 atmospheric calibration curve, and DeltaR in the case of
%			 a marine curve. (default = 0)
%            e.g. 'resage',320 for a reservoir age of 320
%
% reserr:    Optional (parameter name and value). Specify a 1 sigma
%            uncertainty for your chosen resage (default = 0)
%            e.g. 'reserr',50 for an uncertainty of 50
%
% dettype:   Optional (parameter name and value). Choose to handle
%            lab determination and plot as F14C or 14C years (default).
%            Options are '14cyr' (default) or 'f14c'. Not case sensitive.
%            e.g. 'dettype','f14c' to activate F14C mode.
%            If F14C is chosen then lab determination (labdet, laberr)
%            must be inputted as F14C, with resage (and reserr)
%            inputted as the F14C depletion ratio relative to the chosen
%            calibration curve, in per mil notation. This notation has been
%            referred to as d14R by Soulet et al (2016), doi: 10.1017/RDC.2015.22.            
%
% plot:      Optional (parameter name and value). Return a calibration
%            plot to Figure 14. The plot displays the 1 and 2
%            sigma ranges of the calibration curve. The calibraiton
%            curve raw data is also shown if IntCal13 is selected.
%            Specify 1 to plot and 0 not to plot. (default = 1 for Matlab
%            users; default = 0 for Octave users)
%            e.g. 'plot',0 not to plot
%
% saveplot:  Optional (parameter name and value). Save an Adobe PDF of
%            the calibration plot to your working directory. Specify 1
%            to save and 0 not to save. (default = 0) Will be ignored
%            if plotting has been disabled.
%            e.g. 'saveplot',1 to save to your working directory.
%
% plotsize:  Optional (parameter name and value). Set the width and height
%            of the printed figure in cm. (default = 16).
%            e.g. 'plotsize',10 for 10 cm.
%
% fontsize:  Optional (parameter name and value). Set the value of the font
%            size in the output plot. (default = 8)
%            e.g. 'fontsize',12 for a font size of 12.
%
% revxdir:   Optional (parameter name and value). Reverse the plot x-axis.
%            Specify 1 to reverse and 0 not to reverse. (default = 0)
%            e.g. 'revxdir',1 to reverse the x-axis.
%
% Output data
% =================================
%
% p95_4:     n by 3 matrix containing 95.45% calibrated age probability
%            range interval(s) calculated using highest posterior density.
%            Each row contains a probability range in Cols 1 and 2, and
%            the associated probability for that range in Col 3.
%            Probabilities are normalised to between zero and one.
%
% p68_2:     Same as p95_4, but for the 68.27% calibrated range.
%
% calprob:   n by 2 matrix containing an annualised calibrated age
%            probability density function for implementation in, e.g.,
%            age modelling. n is the annualised length of the chosen
%            calibration curve. Col 1 is a series of annual cal ages,
%            Col 2 contains their associated probability. All probabilities
%            are normalised such that they sum to 1.
%
% medage:    Median age calculated from calprob.
%
% Functional examples
% =================================
%
% [p95_4, p68_2, prob, medage] = matcal(1175, 30, 'IntCal20', 'BCE/CE');
% Calibrate a 14C age of 1175±30 14C yr BP using IntCal20 with output in BCE/CE.
%
% [p95_4, p68_2, prob, medage] = matcal(23175, 60, 'Marine20', 'CalBP',...
% 'resage', -50, 'reserr', 100, 'saveplot', 1);
% Calibrate a 14C age of 23175±60 14C yr BP using Marine20, with output in
% Cal BP, with delta-R of -50±100 14C yr and save a copy of the plot to
% your working directory as an Adobe PDF.
%
% [p95_4, p68_2, prob, medage] = matcal(1175, 30, 'IntCal20', 'CalBP', 'plot', 0);
% Calibrate a 14C age of 1175±50 14C yr BP using IntCal20, with output in
% Cal BP and disable the plot window.
%
% ------------
%
% MatCal 3.0 (2020-08-13)
% Originally written using MatLab 2012a, tested compatible with 2019a.
% No toolboxes required.
% Please see manuscript for more information:
% http://doi.org/10.5334/jors.130
matcalvers = 'MatCal (Lougheed and Obrochta, 2016), ver 3.0';

if nargin < 4
	error('Not enough input parameters (see help for instructions)')
end