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: bgtraining.m
    path of file: ./repos/lrslibrary/algorithms/st/GRASTA
    
    the code of the file until where you have to start completion: function [ bgU, status, OPTS ] = bgtraining( videopath, OPTIONS, max_cycles, subsampling, training_size, FPS_ONLY , TRAIN_FRAME)
%BGTRAINING Summary of this function goes here
%   Detailed explanation goes here
thresh = 0.1;

FILE_EXT        = '.bmp';
OPTS            = struct(); % initial a empty struct for OPTS
status.init     = 0;   % status of grasta at each iteration
U_hat           = zeros(1);

%
Dir_lists = dir(videopath);
Video_Length = min(training_size,length(Dir_lists));

if TRAIN_FRAME == 1, % Random selection
    p = randperm(length(Dir_lists)); % length(Dir_lists)-1500 for hall

    
function [ bgU, status, OPTS ] = bgtraining( videopath, OPTIONS, max_cycles, subsampling, training_size, FPS_ONLY , TRAIN_FRAME)
%BGTRAINING Summary of this function goes here
%   Detailed explanation goes here
thresh = 0.1;

FILE_EXT        = '.bmp';
OPTS            = struct(); % initial a empty struct for OPTS
status.init     = 0;   % status of grasta at each iteration
U_hat           = zeros(1);

%
Dir_lists = dir(videopath);
Video_Length = min(training_size,length(Dir_lists));

if TRAIN_FRAME == 1, % Random selection
    p = randperm(length(Dir_lists)); % length(Dir_lists)-1500 for hall
    frames_idx = p(1:Video_Length);
else                % Select all frames
    frames_idx = 1:Video_Length;
end