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

%SIMCAPLOT plots a scatter plot with the boundaries defined by the SIMCA method. 
% It is based on the results from a simca analysis (see rsimca.m or csimca.m).
% 
% For technical reasons, 6 different groups can be plotted (with different symbols).
% In case there are more groups, please adapt lines 15--17.
%
% I/O: simcaplot(result)
%
% Written by K. Vanden Branden on 01/08/04
% Last update: 21/09/2004

p = size(result.x,2);
markings={'bx';'ro';'kdiamond';'y+';'g.';'m*'};
linecolor={'b-','r-','k-','y-','g-','m-'};
colorellipse={'b','r','k','y','g','m'};
if p>3
    error('The dimension of the dataset is larger than 3.')
elseif length(result.avemisclasprob)>6
    error(['Only 6 groups can be drawn with different symbols. Please adapt the code',... 
            ' of simcaplot.m if you want to draw more groups.'])
else

    
function simcaplot(result); 

%SIMCAPLOT plots a scatter plot with the boundaries defined by the SIMCA method. 
% It is based on the results from a simca analysis (see rsimca.m or csimca.m).
% 
% For technical reasons, 6 different groups can be plotted (with different symbols).
% In case there are more groups, please adapt lines 15--17.
%
% I/O: simcaplot(result)
%
% Written by K. Vanden Branden on 01/08/04
% Last update: 21/09/2004

p = size(result.x,2);
markings={'bx';'ro';'kdiamond';'y+';'g.';'m*'};
linecolor={'b-','r-','k-','y-','g-','m-'};
colorellipse={'b','r','k','y','g','m'};
if p>3
    error('The dimension of the dataset is larger than 3.')
elseif length(result.avemisclasprob)>6
    error(['Only 6 groups can be drawn with different symbols. Please adapt the code',... 
            ' of simcaplot.m if you want to draw more groups.'])
else
    legstr=[];
    nClass = length(result.groupmisclasprob);
    for iClass = 1:nClass
        out = result.pca{iClass};
        groupi = result.x(find(result.group == iClass),:);
        %legstr=[legstr; sprintf(['Group',num2str(iClass)])]; 
        if out.k == 1
            [out.lbord,out.rbord]=confreg(out);
            bord=[out.lbord,out.rbord];
        elseif out.k == 2
            bord=ellipse([0 0],diag(out.L(1:2)));
        elseif out.k == 3
            bord=ellips3D(out.M, out.P*diag(out.L)*out.P');
        end