cm_segmentation_of_continuous_data_fieldtrip_20150825.m 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function [new data] = cm_segmentation_of_continuous_data_fieldtrip_20150825(data,cfg)
  2. %
  3. % data = cm_segmentation_of_continuous_data_fieldtrip_20141217(data,cfg)
  4. %
  5. % segmentation of existing continuous fieldtrip data into segments as
  6. % defined by cfg.trl
  7. %
  8. %
  9. % data = fieldtrip data structure (continous data)
  10. % cfg.trl = trial structure (data points relative to the data in the fieldtrip data structure!)
  11. % 17.12.2014 THG
  12. % 25.08.2015 (THG) changed: checks if field .hdr exists
  13. %% get data & update fields
  14. % get fields from original data
  15. if isfield(data,'hdr')
  16. new.hdr = data.hdr;
  17. end
  18. new.label = data.label;
  19. % get data
  20. for j = 1:size(cfg.trl,1)
  21. % time vector
  22. n = cfg.trl(j,2) - cfg.trl(j,1) + 1;
  23. tim = [1/data.fsample:1/data.fsample:n/data.fsample];
  24. new.time{j} = tim; clear tim
  25. % data
  26. new.trial{j} = data.trial{1}(:,cfg.trl(j,1):cfg.trl(j,2));
  27. end; clear j
  28. % update fields
  29. new.fsample = data.fsample;
  30. new.sampleinfo = cfg.trl(:,1:2);