ftraw.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function raw = ftraw(this, chanind, timeind, trialind)
  2. % Method for converting meeg object to Fieldtrip raw struct
  3. % FORMAT raw = ftraw(this, chanind, timeind, trialind)
  4. % _______________________________________________________________________
  5. % Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
  6. % Vladimir Litvak
  7. % $Id: ftraw.m 6158 2014-09-09 12:23:49Z vladimir $
  8. if ~islinked(this)
  9. error('There is no data linked to the object');
  10. end
  11. if ~isequal(transformtype(this), 'time')
  12. raw = fttimelock(this, chanind, timeind, trialind);
  13. return;
  14. end
  15. % chanind == 0 is accepted for backward compatibility
  16. if nargin < 2 || ~isnumeric(chanind) || isequal(chanind, 0)
  17. chanind = 1:nchannels(this);
  18. end
  19. if nargin < 3 || ~isnumeric(timeind)
  20. timeind = 1:nsamples(this);
  21. end
  22. if nargin < 4 || ~isnumeric(trialind)
  23. trialind = 1:ntrials(this);
  24. end
  25. raw = [];
  26. raw.label = chanlabels(this, chanind)';
  27. raw.trial = cell(1, length(trialind));
  28. for i = 1:length(trialind)
  29. raw.trial{i} = subsref(this, substruct('()', {chanind, timeind, trialind(i)}));
  30. end
  31. raw.time = repmat({time(this, timeind)}, 1, length(trialind));
  32. clist = condlist(this);
  33. condlabels = conditions(this, trialind);
  34. raw.trialinfo = 0*trialind;
  35. for k = 1:numel(clist)
  36. fprintf('mapping condition label "%s" to condition code %d\n', clist{k}, k);
  37. sel = strcmp(clist{k}, condlabels);
  38. raw.trialinfo(sel) = k;
  39. end
  40. if ~isempty(sensors(this, 'MEG'))
  41. raw.grad = sensors(this, 'MEG');
  42. end
  43. if ~isempty(sensors(this, 'EEG'))
  44. raw.elec = sensors(this, 'EEG');
  45. end
  46. if isfield(this.other, 'origheader')
  47. raw.hdr = this.other.origheader;
  48. end
  49. onsets = trialonset(this, trialind);
  50. if all(onsets>0)
  51. onsets = round(onsets(:)*fsample(this));
  52. raw.sampleinfo = [onsets+timeind(1) onsets+timeind(end)]-1;
  53. end