close all
%clearvar -except AllData

MatlabFilename = 'AllData.mat';
if(~exist('AllData'))
  AllData = load(MatlabFilename);
end

SegmentNames{1} = 'Monday';

StartDateNum = [datenum('2-Oct-2017 18:00:00') ];
EndDateNum =   [datenum('2-Oct-2017 21:00:00') ];            

varList = fieldnames(AllData);

for  k = 1:length(SegmentNames)
    
  idx = find((AllData.Time_DateNum < EndDateNum(k))& (AllData.Time_DateNum > StartDateNum(k)));
  for j = 1:length(varList)
    cmd = [varList{j} ' = AllData.' varList{j} '(idx,:);'];
    eval(cmd);
  end
  save(SegmentNames{k},'Time_DateNum','PC_*','BC_*','SC_*','RC_*','XB_*');
end
