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: concatenate.m
    path of file: ./repos/CanlabCore/CanlabCore/@canlab_dataset
    
    the code of the file until where you have to start completion: function [names, ids, dat, descrips] = concatenate(D, varargin)
% Concatenates Subject-level and Event-level data across all subjects
%
% :Usage:
% ::
%
%    [names ids dat] = concatenate(D, [optional inputs])
%
% :Inputs:
%
%   **D:**
%        canlab_dataset object
%
% :Optional Inputs:
%   **a logical array**
%       a vector of 1/0 values to use as wh_keep
%
%
% :Outputs:
%
%   **names:**
%        cell array of variable names
%
%   **ids:**
%        subject IDs matching data rows in dat
%
%   **dat:**
%        subjects*events x variables matrix
%           - subject number, event number are included
%           - all subject-level and event-level data are included
%           - this format appropriate for, e.g., SAS/HLM
%
%   **descrips:**
%        cell array of variable descriptions
%
% :Examples:
% ::
%
%    [names, ids, flatdat] = concatenate(D);
%    id_numbers = flatdat(:, 1);
%
%    wh_subjs = true(size(D.Subj_Level.id));
%    wh_subjs([13 18 19]) = false;
%    [names, ids, dat] = concatenate(D, wh_subjs);
%

% ..
%     Author and copyright information:
%
%     Copyright (C) 2013 Tor Wager
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
% ..

    
function [names, ids, dat, descrips] = concatenate(D, varargin)
% Concatenates Subject-level and Event-level data across all subjects
%
% :Usage:
% ::
%
%    [names ids dat] = concatenate(D, [optional inputs])
%
% :Inputs:
%
%   **D:**
%        canlab_dataset object
%
% :Optional Inputs:
%   **a logical array**
%       a vector of 1/0 values to use as wh_keep
%
%
% :Outputs:
%
%   **names:**
%        cell array of variable names
%
%   **ids:**
%        subject IDs matching data rows in dat
%
%   **dat:**
%        subjects*events x variables matrix
%           - subject number, event number are included
%           - all subject-level and event-level data are included
%           - this format appropriate for, e.g., SAS/HLM
%
%   **descrips:**
%        cell array of variable descriptions
%
% :Examples:
% ::
%
%    [names, ids, flatdat] = concatenate(D);
%    id_numbers = flatdat(:, 1);
%
%    wh_subjs = true(size(D.Subj_Level.id));
%    wh_subjs([13 18 19]) = false;
%    [names, ids, dat] = concatenate(D, wh_subjs);
%

% ..
%     Author and copyright information:
%
%     Copyright (C) 2013 Tor Wager
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
% ..
%

wh_ids = true(length(D.Subj_Level.id), 1); % select subjects
if length(varargin) > 0, wh_ids = logical(varargin{1}); end