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: predict.m
    path of file: ./repos/bspm/thirdparty/corr_toolbox_v2/LIBRA
    
    the code of the file until where you have to start completion: function result=predict(x,y,inmodel)

%PREDICT is a function which computes regression results for new data based on
% the output from a RPCR or RSIMPLS analysis.
%
% I/O: result=predict(x,y,inmodel)
%
% Required input arguments:
%   x: Data matrix of the explanatory variables of the new data
%   y: Data matrix of the response variables of the new data
%   inmodel: output from a RPCR or RSIMPLS model
%
% The output of PREDICT is a structure containing:
%
%   result.fitted  : Fitted response values of the new data
%   result.res     : Residuals of the new data 
%   result.sd      : Score distances of the new data 
%   result.od      : Orthogonal distances of the new data
%   result.resd    : Residual distances of the new data
%   result.cutoff  : Cutoff values for the score (result.cutoff.sd), orthogonal 
%                         (result.cutoff.od) and residual distances (result.cutoff.resd).
%                         We use 0.99 quantiles of the chi-squared distribution.            
%   result.flag    : The observations whose score distance is larger than 
%                    'result.cutoff.sd' receive a flag 'result.flag.sd' equal
%                    to zero (good leverage points). Otherwise 'result.flag.sd'
%                    is equal to one. 
%                    The components 'result.flag.od' and 'result.flag.resd' are
%                    defined analogously, and determine the orthogonal outliers, 
%                    resp. the bad leverage points/vertical outliers. 
%                    The observations with 'result.flag.od' and 'result.flag.resd'
%                    equal to zero, can be considered as calibration outliers and receive
%                    'result.flag.all' equal to zero. The regular observations and the good leverage
%                     points have 'result.flag.all' equal to one.
%   result.rmsep  : the root mean squared error of the 
%                        .outlfree : non-outlying data 
%                        .trimh     : trimmed according to 'h' smallest residuals (=h from the inmodel)
%                        .trim50   : trimmed at 50% of the smallest residuals
%                        .trim75   : trimmed at 75% of the smallest residuals

    
function result=predict(x,y,inmodel)

%PREDICT is a function which computes regression results for new data based on
% the output from a RPCR or RSIMPLS analysis.
%
% I/O: result=predict(x,y,inmodel)
%
% Required input arguments:
%   x: Data matrix of the explanatory variables of the new data
%   y: Data matrix of the response variables of the new data
%   inmodel: output from a RPCR or RSIMPLS model
%
% The output of PREDICT is a structure containing:
%
%   result.fitted  : Fitted response values of the new data
%   result.res     : Residuals of the new data 
%   result.sd      : Score distances of the new data 
%   result.od      : Orthogonal distances of the new data
%   result.resd    : Residual distances of the new data
%   result.cutoff  : Cutoff values for the score (result.cutoff.sd), orthogonal 
%                         (result.cutoff.od) and residual distances (result.cutoff.resd).
%                         We use 0.99 quantiles of the chi-squared distribution.            
%   result.flag    : The observations whose score distance is larger than 
%                    'result.cutoff.sd' receive a flag 'result.flag.sd' equal
%                    to zero (good leverage points). Otherwise 'result.flag.sd'
%                    is equal to one. 
%                    The components 'result.flag.od' and 'result.flag.resd' are
%                    defined analogously, and determine the orthogonal outliers, 
%                    resp. the bad leverage points/vertical outliers. 
%                    The observations with 'result.flag.od' and 'result.flag.resd'
%                    equal to zero, can be considered as calibration outliers and receive
%                    'result.flag.all' equal to zero. The regular observations and the good leverage
%                     points have 'result.flag.all' equal to one.
%   result.rmsep  : the root mean squared error of the 
%                        .outlfree : non-outlying data 
%                        .trimh     : trimmed according to 'h' smallest residuals (=h from the inmodel)
%                        .trim50   : trimmed at 50% of the smallest residuals
%                        .trim75   : trimmed at 75% of the smallest residuals
%                        .trim95   : trimmed at 95% of the smallest residuals
%   result.class   : the name of the method used: 'RPCR' or 'RSIMPLS'
%   result.classic : if there was a classical output from rpcr or rsimpls,
%                    all computations based on these classical results are 
%                    done as well. Note that the root mean squared error is 
%                    then based on the non-outlying data from the robust
%                    analysis, in order to compare the rmsep values on the
%                    same data set.
%   
% Example:
%  out.pcr = rpcr(Xtrain,ytrain,'k',3,'plots',0);
%  result  = predict(Xtest,ytest,out.pcr);
%
% Written by S. Verboven, M. Hubert 
% Last Revision: 20/05/2008
% Last Update: 30/05/2008

X=x;
Y=y;
[n,p]=size(X);
[n,q]=size(Y);

%Fitted values and residuals of the new data
result.fitted=X*inmodel.slope + repmat(inmodel.int,n,1);
result.res=Y-result.fitted;

%Computing distances
if strcmp(inmodel.class,'RPCR')
    XRc=X-repmat(inmodel.robpca.M,n,1);
    result.T=XRc*inmodel.robpca.P;
    result.sd=sqrt(mahalanobis(result.T,zeros(size(result.T,2),1),'cov',inmodel.robpca.L))';
    Xtilde=result.T*inmodel.robpca.P';
    Rdiff=XRc-Xtilde;
    for i=1:n
        result.od(i,1)=norm(Rdiff(i,:));
    end