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: DrawStressEllipsoidsPrincipal.m
    path of file: ./repos/CutAndDisplace/3dCode/SimpleExternalFunctions
    
    the code of the file until where you have to start completion: function  DrawStressEllipsoidsPrincipal(StressTensor,StrainTensor,X,Y,Z,varargin)
% DrawStressEllipsoidsPrincipal: Draws the principal stress ellipsoids, 
%                   pretty intensive function so can be quite slow. A catch
%                   exists to stop users putting too much data into this
%                   and taking forever.
%
%                   Results show as red ellipsoids when the dilatation is
%                   positive and blue when negative.
%
%                   This also draws a triangulated surface if you supply
%                   this in the varargin. 
%               
% usage #1:
% DrawStressEllipsoidsPrincipal(StressTensor,StrainTensor,X,Y,Z,'Scale',2)
%
% Arguments: (input)
% StressTensor      - From the stress calculation 6*n vector, 
%                    [Sxx,Syy,Szz,Sxy,Sxz,Syz]
%
% StrainTensor      - From the strain calculation 6*n vector, 
%                    [Exx,Eyy,Ezz,Exy,Exz,Eyz]
%
% XYZ               - The XYZ locations of the points where the tensors are.
%
% Additional arguments: (input)
%
% Scale             - Property changing the length of the 
%                    resultant ellipsoid. (Single value)  
%
% Sample            - Properties changing the sampling of the 
%                    resultant ellipsoid. (Single value). Its the amount of
%                    points/faces that make up each ellipsoid in plot, the
%                    points are Sample^2. Reduce this number if figure is
%  
    
function "DrawStressEllipsoidsPrincipal.m", too many input points')
    disp('It is recommended to use a few points at first to get the parameters right.')
    return
end

figure;

%Forcing XYZ to column vecs 
Xcv=X(:); %col vecs
Ycv=Y(:); %col vecs
Zcv=Z(:); %col vecs

%Extracting strain & stress
[Sxx,Syy,Szz,Sxy,Sxz,Syz ] = ExtractCols( StressTensor );
[Exx,Eyy,Ezz,Exy,Exz,Eyz ] = ExtractCols( StrainTensor );
%Calculating principal stresses
[S1,S2,S3,S1dir,S2dir,S3dir] = EigCalc3d(Sxx(:),Syy(:),Szz(:),Sxy(:),Sxz(:),Syz(:));
%Calculating principal strains to calculate dilatation. (if vol change is
%positive or negative for drawing
[E1,E2,E3] = EigCalc3d(Exx(:),Eyy(:),Ezz(:),Exy(:),Exz(:),Eyz(:));
Dilatation=E1+E2+E3; %(Change/Orig vol)
Expanded=Dilatation(:)>0; %flag, positive is expansion

%Init Dims Outside lp
dimx = Sample+1;
dimy = Sample+1;  

%Now drawing first subplot
%This is a figure showing vectors that are the principal directions.
%Coloured for S1S2S3 and sign, see fig title for col details 
for i=1:numel(S1)
    %Creating the ellipsoid
    [x,y,z] = ellipsoid(0,0,0,S1(i)*Scale,S2(i)*Scale,S3(i)*Scale,Sample); %Very low sampling
    
    %Rotating points to each direction cosine
    [xn,yn,zn] = RotateObject3dNewCoords(S1dir(i,:),S2dir(i,:),S3dir(i,:),x,y,z);

    %Reshape
    [xn,yn,zn]=ReshapeData2d( dimx,dimy, xn,yn,zn );
    
    
    %Moving the points to the correct location in space
    xn=xn+Xcv(i,:);
    yn=yn+Ycv(i,:);
    zn=zn+Zcv(i,:);

    [ C ] = RGB2Colour(0,191,255);

        %Drawing a single ellipsoid then setting the colour based on the total volume change sign at this
        %infinitesimal point. 
        if Expanded(i)==1
            hSurface=surf(xn, yn, zn);
            if  isOctave==1
                set(hSurface,'FaceColor','red','EdgeColor',([0.3;0.3;0.3]));%lighting not setup for surfaces in octave
            elseif isOctave==0
                set(hSurface,'FaceColor','red','FaceLighting','gouraud','EdgeColor',([0.3;0.3;0.3])); 
            end