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: TS_PlotTimeSeries.m
    path of file: ./repos/hctsa/PlottingAnalysis
    
    the code of the file until where you have to start completion: function TS_PlotTimeSeries(whatData,numPerGroup,whatTimeSeries,maxLength,plotOptions)
% TS_PlotTimeSeries    Plots examples of time series in an hctsa analysis.
%
%---INPUTS:
% whatData, The hctsa data to load information from (cf. TS_LoadData) [or can
%               specify a TimeSeries table directly]
%
% numPerGroup, If plotting groups, plots this many examples per group
%
% whatTimeSeries, Can provide indices to plot that subset, a keyword to plot
%                   matches to the keyword, 'all' to plot all, or an empty vector
%                   to plot group information assigned to TimeSeries.Group
%
% maxLength, the maximum number of samples of each time series to plot
%
% plotOptions, additional plotting options as a structure

% ------------------------------------------------------------------------------
% Copyright (C) 2020, Ben D. Fulcher <ben.d.fulcher@gmail.com>,
% <http://www.benfulcher.com>
%
% If you use this code for your research, please cite the following two papers:
%
% (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated
% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).
% DOI: 10.1016/j.cels.2017.10.001
%
% (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series
% analysis: the empirical structure of time series and their methods",
% J. Roy. Soc. Interface 10(83) 20130048 (2013).
% DOI: 10.1098/rsif.2013.0048
%
% This work is licensed under the Creative Commons
% Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of
% this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send
% a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View,
% California, 94041, USA.
% ------------------------------------------------------------------------------

% ------------------------------------------------------------------------------
%% Check Inputs
% ------------------------------------------------------------------------------
% Get time-series data from where? ('norm' by default)
if nargin < 1 || isempty(whatData)
    whatData = 'raw';
end

if nargin < 2 || isempty(numPerGroup)
    % Default: plot 10 time series per group
    numPerGroup = 10;
end

    
function TS_PlotTimeSeries(whatData,numPerGroup,whatTimeSeries,maxLength,plotOptions)
% TS_PlotTimeSeries    Plots examples of time series in an hctsa analysis.
%
%---INPUTS:
% whatData, The hctsa data to load information from (cf. TS_LoadData) [or can
%               specify a TimeSeries table directly]
%
% numPerGroup, If plotting groups, plots this many examples per group
%
% whatTimeSeries, Can provide indices to plot that subset, a keyword to plot
%                   matches to the keyword, 'all' to plot all, or an empty vector
%                   to plot group information assigned to TimeSeries.Group
%
% maxLength, the maximum number of samples of each time series to plot
%
% plotOptions, additional plotting options as a structure

% ------------------------------------------------------------------------------
% Copyright (C) 2020, Ben D. Fulcher <ben.d.fulcher@gmail.com>,
% <http://www.benfulcher.com>
%
% If you use this code for your research, please cite the following two papers:
%
% (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated
% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).
% DOI: 10.1016/j.cels.2017.10.001
%
% (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series
% analysis: the empirical structure of time series and their methods",
% J. Roy. Soc. Interface 10(83) 20130048 (2013).
% DOI: 10.1098/rsif.2013.0048
%
% This work is licensed under the Creative Commons
% Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of
% this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send
% a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View,
% California, 94041, USA.
% ------------------------------------------------------------------------------

% ------------------------------------------------------------------------------
%% Check Inputs
% ------------------------------------------------------------------------------
% Get time-series data from where? ('norm' by default)
if nargin < 1 || isempty(whatData)
    whatData = 'raw';
end

if nargin < 2 || isempty(numPerGroup)
    % Default: plot 10 time series per group
    numPerGroup = 10;
end
if numPerGroup==0
    error('numPerGroup cannot be zero');
end

% Can specify a reduced set of time series by keyword (or indices)
if nargin < 3
    whatTimeSeries = '';
end

if nargin < 4
    % Maximum length of time series to display (otherwise crops)
    % If empty, displays all of all time series
    maxLength = [];
end

if nargin < 5
	plotOptions = [];
end

%-------------------------------------------------------------------------------
% Evaluate any custom plotting options specified in the structure plotOptions
%-------------------------------------------------------------------------------
if isstruct(plotOptions) && isfield(plotOptions,'displayTitles')
    displayTitles = plotOptions.displayTitles;
else
    % Show titles -- removing them allows more to be fit into plot
    displayTitles = true; % show titles by default
end
if isstruct(plotOptions) && isfield(plotOptions,'howToFilter')
    howToFilter = plotOptions.howToFilter;
else
    howToFilter = 'evenly'; % by default
    % 'firstcome' (first time series in order)
    % 'evenly' (evenly spaced across the ordering)
    % 'rand' (random set; picks different time series each time)
end
% Specify the colormap to use
if isstruct(plotOptions) && isfield(plotOptions,'colorMap')
    colorMap = plotOptions.colorMap;
else
    colorMap = ''; % choose automatically using GiveMeColors
end
% Specify whether to make a free-form plot
if isstruct(plotOptions) && isfield(plotOptions,'plotFreeForm')
    plotFreeForm = plotOptions.plotFreeForm;
else
    plotFreeForm = true; % do a normal subplotted figure
end
% Specify line width for plotting
if isstruct(plotOptions) && isfield(plotOptions,'LineWidth')
    lw = plotOptions.LineWidth;
else
    lw = 1; % do a normal subplotted figure
end
% Determine whether to create a new figure
if isstruct(plotOptions) && isfield(plotOptions,'newFigure')
    newFigure = plotOptions.newFigure;
else
    newFigure = true;
end
% Sorting time series by length can help visualization
if isstruct(plotOptions) && isfield(plotOptions,'sortByLength')
    sortByLength = plotOptions.sortByLength;
else
    sortByLength = false;
end
% Carpet plot instead...?
if isstruct(plotOptions) && isfield(plotOptions,'carpetPlot')
    carpetPlot = plotOptions.carpetPlot;
else
    carpetPlot = false;
end

% ------------------------------------------------------------------------------
%% Load TimeSeries table
% ------------------------------------------------------------------------------
if istable(whatData)
    TimeSeries = whatData;
else
    TimeSeries = TS_GetFromData(whatData,'TimeSeries');
end