function [ts, I] = getTimeSeries(h,varargin)

%% Extacts time series objects from the timeplot @Data as a cell array (if
%% no name is specified) or as a single @timeseries if a name is specified

I = [];
if nargin ==1 % Get all time series
    ts = {};
    for k = 1:length(h.Waves)
        if ~isempty(h.Waves(k).DataSrc.Timeseries)
           ts = [ts; {h.Waves(k).DataSrc.Timeseries}];
           I = [I; k];
        end
    end
else % Get time series by name
    ts = [];
    for k = 1:length(h.Waves)
        if ~isempty(h.Waves(k).DataSrc.Timeseries) && ...
                strcmp(h.Waves(k).DataSrc.Timeseries.Name,varargin{1})
           ts = h.Waves(k).DataSrc.Timeseries;
           I = k;
           break
        end
    end
end