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: exactfrsd.m
    path of file: ./repos/CanlabCore/CanlabCore/Statistics_tools
    
    the code of the file until where you have to start completion: % Nonparametric test for exact likelihoods of pairwise contrasts in a 
% repeated measures design. Is to the Friedman test as a Tukey test is 
% to an rm-ANOVA.
% function p = exactfrsd(d,k,n)
%
% Output ::
%
%   p 	- Likelihood under the null (both groups equal). aka pValue
%
% Input ::
%
%   d 	- sum of Friedman rank difference. These can be obtained with 
%       	a = multcompare(friedman(data)); ranksum = n*a(:,4)
%   k	- number of treatments (e.g. classifiers) tested
%   n 	- number of groups (e.g. datasets)
    
function p = exactfrsd(d,k,n)
%
% Output ::
%
%   p 	- Likelihood under the null (both groups equal). aka pValue
%
% Input ::
%
%   d 	- sum of Friedman rank difference. These can be obtained with 
%       	a = multcompare(friedman(data)); ranksum = n*a(:,4)
%   k	- number of treatments (e.g. classifiers) tested
%   n 	- number of groups (e.g. datasets) on which repeated measures were 
%           evaluated
%
% adapted from R code. Cite 
% Eisinga R, Heskes T, Pelzer B, Grontenhuis MT (2017) "Exact p-values for 
%   pairwise comparison of Friedman rank sums, with applications to 
%   comparing classifiers". BMC Bioinformatics 18:68.
%
% shamelessly copied from the author's published R script by Bogdan Petre
% April, 2020
%
% Warning: These computations can involve large numbers. The R script (and
% the original paper) solves numerical overflow problems using an R package
% for arbitrary precision arithmetic. We use matlab's vpa() function but
% this is not tested carefully. If in doubt I would defer to the R code.
function p = exactfrsd(d, k, n)
    if n < 1, error('n >= 1 please'); end