% epoch2continuous (alpha version)
%
% epoch2continuous.m converts an epoched dataset into a continuous one.
% Segments of data will be concatenated using a 'boundary' event.
%
% USAGE
%
% EEG = epoch2continuous(EEG);
%
% *** This function is part of ERPLAB Toolbox ***
% Author: Javier Lopez-Calderon
% Center for Mind and Brain
% University of California, Davis,
% Davis, CA
% July 7, 2011
%
% Feedback would be appreciated and credited.
% NOTE: No ICA fields have been tested until this version.
% BUG #1: EEG.epoch.eventlatency cell vs single value. Steven Raaijmakers

function [EEG com] = pop_epoch2continuous(EEG)
com = '';
if nargin<1
      help pop_epoch2continuous
      return
end
if length(EEG)>1
      msgboxText =  'Unfortunately, this function does not work with multiple datasets';
      title = 'ERPLAB: multiple inputs';
      errorfound(msgboxText, title);
      return
end
if isempty(EEG.data)
      msgboxText = 'pop_epoch2continuous() cannot read an empty dataset!';
      title = 'ERPLAB: pop_epoch2continuous';
      errorfound(msgboxText, title);
      return
end
if isempty(EEG.epoch)
      msgboxText = 'pop_epoch2continuous is intended to work with epoched datasets only. ';
      title = 'ERPLAB: pop_epoch2continuous ';
      errorfound(msgboxText, title);
      return
end

EEG = epoch2continuous(EEG);
EEG.setname = [EEG.setname '_ep2con'];
EEG.EVENTLIST = []; % remove EVENTLIST structure

com = sprintf('%s = pop_epoch2continuous(%s);', inputname(1), inputname(1));
%
% Completion statement
%
msg2end