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: bramila_maskrois.m
    path of file: ./repos/bspm/thirdparty/bramila
    
    the code of the file until where you have to start completion: function [blacklist,roimask,new_rois] = bramila_maskrois(rois,mask,limit_percentage)
% bramila_create_blacklist.m, returns a list of ROIs that are outside given mask.
% IN:
% rois = roi structure (contains at least a field 'map')
% mask = 3D mask of interest (values 0 are outside mask)
% limit_percentage = roi must contain at least this many voxels compared to roi definition, range (0,1] (OPTIONAL)
% OUT:
% blacklist = list of bad rois
% roimask = mask of good rois with each roi uniquely numbered (OPTIONAL)
% new_rois = modified roi structure with only good rois remaining (OPTIONAL)

% has much voxels must remain inside roi (0.50 = 50%), otherwise roi is marked as bad
if nargin<3

    
function [blacklist,roimask,new_rois] = bramila_maskrois(rois,mask,limit_percentage)
% bramila_create_blacklist.m, returns a list of ROIs that are outside given mask.
% IN:
% rois = roi structure (contains at least a field 'map')
% mask = 3D mask of interest (values 0 are outside mask)
% limit_percentage = roi must contain at least this many voxels compared to roi definition, range (0,1] (OPTIONAL)
% OUT:
% blacklist = list of bad rois
% roimask = mask of good rois with each roi uniquely numbered (OPTIONAL)
% new_rois = modified roi structure with only good rois remaining (OPTIONAL)

% has much voxels must remain inside roi (0.50 = 50%), otherwise roi is marked as bad
if nargin<3
    limit_percentage = 0.5;
else
   if limit_percentage<=0 || limit_percentage>1
      error('Limit percentage must be between (0,1]') 
   end