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: subBoundarySize.m
    path of file: ./repos/mtex/EBSDAnalysis/@grain2d
    
    the code of the file until where you have to start completion: function  numSec = subBoundarySize(grains,varargin)
% number of subgrain boundary segments
%
% Input
%  grains - @grain2d
%
% Output
%  numSec - number of boundary segments

    
function  numSec = subBoundarySize(grains,varargin)
% number of subgrain boundary segments
%
% Input
%  grains - @grain2d
%
% Output
%  numSec - number of boundary segments
%
% Syntax
%   numSec = grains.boundarySize
%


grainIds = grains.innerBoundary.grainId;

% if varargin is a logical use for selection of relevant innerBoundary
if nargin>1 && islogical(varargin{1})
  grainIds = grainIds(varargin{1},:);
end