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: stratified_holdout_set.m
    path of file: ./repos/CanlabCore/CanlabCore/Statistics_tools/Support_functions
    
    the code of the file until where you have to start completion: function cvpart = stratified_holdout_set(Y, varargin)
% cvpart = stratified_holdout_set(Y, [nfolds or integer vector for holdout set ID], [optional keywords])
%

    
function cvpart = stratified_holdout_set(Y, varargin)
% cvpart = stratified_holdout_set(Y, [nfolds or integer vector for holdout set ID], [optional keywords])
%
% CANlab holdout set identification 
% Simple stratified holdout set, stratifying on level of Y
%
% Use cases:
% -------------------------------------------------------------------
% stratified_holdout_set(Y, [vector of integers length Y])
% Custom holdout set
% Returns folds specified in integers
% fold_indicator is a copy of the input vector of integers
% nfolds is based on unique elements in vector of integers
%
% stratified_holdout_set(Y)
% 5-fold stratified holdout set; see below
%
% stratified_holdout_set(Y, 1)
% Use all obs for train and test; good for bootstrapping weights
%
% stratified_holdout_set(Y, nfolds)
% Returns number of folds specified in nfolds 
% If Y is categorical: Uses cvpartition (matlab) to stratify on class ID
% specified in Y
% If Y is continuous: holdout sets are every nth entry in an ordered
% (sorted) list of Y values
%
% stratified_holdout_set(Y, 'rolling', [h v g])
% Returns rolling HVG block holdout set
% h = window length for test set
% v = window length for buffer
% g = window length for training set
%
% stratified_holdout_set(Y, 'hvblock', [h v])
% Returns rolling HVG block holdout set
% h = window length for test set
% v = window length for buffer
% (all other observations are in training set)
% needs 2 * h + 2 * v observations
%
% Examples:
% 
% 3-fold on random variable:
% cvpart = stratified_holdout_set(rand(100, 1), 3)
%
% Create and visualize rolling hv block
% cvpart = stratified_holdout_set(rand(100, 1), 'hvblock', [5 5]);
% cat(2, cvpart.teIdx{:}) - cat(2, cvpart.trIdx{:})
% testvstrain = cat(2, cvpart.teIdx{:}) - cat(2, cvpart.trIdx{:})
% figure; imagesc(testvstrain);


% ---------------------------------------------------------------------
% Defaults
% ---------------------------------------------------------------------

nfolds = 5;
tsxval_hvblock = 0;
tsxval_rolling = 0;
fold_indicator = ones(size(Y));

for i = 1:length(varargin)
    if ~ischar(varargin{i})
        % number: nfolds or holdout set integer vector (parsed below)
        nfolds = varargin{i};  
        
    else
        % keywords
        switch varargin{i}
                
            case 'rolling'
                tsxval_rolling = 1;
                inval = varargin{i + 1};
                h = inval(1);
                v = inval(2);
                g = inval(3);
                varargin{i} = [];
                varargin{i + 1} = [];
                
            case 'hvblock'
                tsxval_hvblock = 1;
                inval = varargin{i + 1};
                h = inval(1);
                v = inval(2);
                varargin{i} = [];
                varargin{i + 1} = [];
                
            otherwise
                warning(['Unknown input: ' varargin{i}])     
                
        end