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: plotHRF.m
    path of file: ./repos/CanlabCore/CanlabCore/HRF_Est_Toolbox2/EstHRF_inAtlas
    
    the code of the file until where you have to start completion: function [model, models]=plotHRF(HRF, varargin)
    % Generates a plot from an HRF Structure given a specified fit type and a region name.
    % Michael Sun, Ph.D.
    % - Takes HRF Structure object generated from EstimateHRF_inAtlas()
    % - d is for selecting which data to plot, default is to aggregate them
    % all. Putting a vector plots each file separately in order e.g., [1 2 3]
    % - 'fit', t is a cellstring for fit type e.g., 'FIR', 'sFIR', 'IL', 'CHRF0', 'CHRF1', 'CHRF2'
    % - 'conditions', c is a cellstring for condition names or stems to plot e.g., {'*hot*, *warm*'}
    % - 'regions', r is a cellstring for region label from atlas.labels. e.g., 'ACC', or a cell-array of regions to compare relative to each other e.g., {'ACC', 'DLPFC'}  
    %
    % *Usage:
    % ::
    %    plotHRF(HRF_structure, 'FIR', 'CA2_Hippocampus_')

    % Check if the specified region 'r' and type 't' exist in HRF
    % Requires the MATlab Signal Processing Toolbox to run
    % detectPeaksandTroughs()

    % Flags to keep track of whether a cell array or atlas object is found
    % isCellArrayFound = false;

    isAtlasFound = false;
    isRegsFound = false;
    isCondFound = false;
    isFitFound = false;

    r=[];



    % Get the list of conditions from HRF_PARAMS

    
function [model, models]=plotHRF(HRF, varargin)
    % Generates a plot from an HRF Structure given a specified fit type and a region name.
    % Michael Sun, Ph.D.
    % - Takes HRF Structure object generated from EstimateHRF_inAtlas()
    % - d is for selecting which data to plot, default is to aggregate them
    % all. Putting a vector plots each file separately in order e.g., [1 2 3]
    % - 'fit', t is a cellstring for fit type e.g., 'FIR', 'sFIR', 'IL', 'CHRF0', 'CHRF1', 'CHRF2'
    % - 'conditions', c is a cellstring for condition names or stems to plot e.g., {'*hot*, *warm*'}
    % - 'regions', r is a cellstring for region label from atlas.labels. e.g., 'ACC', or a cell-array of regions to compare relative to each other e.g., {'ACC', 'DLPFC'}  
    %
    % *Usage:
    % ::
    %    plotHRF(HRF_structure, 'FIR', 'CA2_Hippocampus_')

    % Check if the specified region 'r' and type 't' exist in HRF
    % Requires the MATlab Signal Processing Toolbox to run
    % detectPeaksandTroughs()

    % Flags to keep track of whether a cell array or atlas object is found
    % isCellArrayFound = false;

    isAtlasFound = false;
    isRegsFound = false;
    isCondFound = false;
    isFitFound = false;

    r=[];



    % Get the list of conditions from HRF_PARAMS
    conds = HRF.CondNames;

    for k = 1:length(varargin)
        if strcmpi(varargin{k}, 'atlas')
            if isa(varargin{k+1}, 'atlas')
                at=varargin{k+1};
            else
                error('Passed in atlas not an atlas.');
            end