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: cpderr.m
    path of file: ./repos/mtt/libs/tensorlab
    
    the code of the file until where you have to start completion: function [relerr,P,D] = cpderr(U,Uest)
%CPDERR Errors between factor matrices in a CPD.
%   [relerr,P,D] = cpderr(U,Uest) computes the relative difference in
%   Frobenius norm between the factor matrix U{n} and the estimated factor
%   matrix Uest{n} as
%
%      relerr(n) = norm(U{n}-Uest{n}*P*D{n},'fro')/norm(U{n},'fro')
%
%   in which the matrices P and D{n} are a permutation and scaling matrix

    
function [relerr,P,D] = cpderr(U,Uest)
%CPDERR Errors between factor matrices in a CPD.
%   [relerr,P,D] = cpderr(U,Uest) computes the relative difference in
%   Frobenius norm between the factor matrix U{n} and the estimated factor
%   matrix Uest{n} as
%
%      relerr(n) = norm(U{n}-Uest{n}*P*D{n},'fro')/norm(U{n},'fro')
%
%   in which the matrices P and D{n} are a permutation and scaling matrix
%   such that the estimated factor matrix Uest{n} is optimally permuted and
%   scaled to fit U{n}. If size(Uest{n},2) > size(U{n},2), then P selects
%   size(U{n},2) rank-one terms of Uest that best match those in U. If
%   size(Uest{n},2) < size(U{n},2), then P pads the rank-one terms of Uest
%   with rank-zero terms. Furthermore, it is important to note that the
%   diagonal matrices D{n} are not constrained to multiply to the identity
%   matrix. In other words, relerr(n) returns the relative error between
%   U{n} and Uest{n} independ