fttimelock.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. function timelock = fttimelock(this, chanind, timeind, trialind, freqind)
  2. % Method for converting meeg object to Fieldtrip timelock/freq struct
  3. % FORMAT timelock = fttimelock(this, chanind, timeind, trialind, freqind)
  4. %
  5. % The method support both time and TF data and outputs different variants
  6. % of timelock or freq FT struct depending on the dataset type and requested
  7. % data dimensions.
  8. % _______________________________________________________________________
  9. % Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
  10. % Vladimir Litvak
  11. % $Id: fttimelock.m 6158 2014-09-09 12:23:49Z vladimir $
  12. if ~islinked(this)
  13. error('There is no data linked to the object');
  14. end
  15. if nargin < 2 || ~isnumeric(chanind)
  16. chanind = 1:nchannels(this);
  17. end
  18. if nargin < 3 || ~isnumeric(timeind)
  19. timeind = 1:nsamples(this);
  20. end
  21. if nargin < 4 || ~isnumeric(trialind)
  22. trialind = 1:ntrials(this);
  23. end
  24. if strncmpi(transformtype(this),'TF',2) && ...
  25. (nargin < 5 || isempty(freqind))
  26. freqind = 1:nfrequencies(this);
  27. end
  28. timelock = [];
  29. timelock.label = chanlabels(this, chanind)';
  30. if isequal(transformtype(this), 'time')
  31. if isequal(type(this), 'continuous')
  32. error('For continuous data use ftraw method');
  33. end
  34. if isequal(type(this), 'single') || length(trialind)>1
  35. timelock.dimord = 'rpt_chan_time';
  36. timelock.trial = permute(subsref(this, substruct('()', {chanind, timeind, trialind})), [3 1 2]);
  37. else
  38. timelock.dimord = 'chan_time';
  39. timelock.avg = spm_squeeze(subsref(this, substruct('()', {chanind, timeind, trialind})), 3);
  40. end
  41. timelock.time = time(this, timeind);
  42. elseif strncmpi(transformtype(this),'TF',2)
  43. if length(timeind)>1
  44. if isequal(type(this), 'single') || length(trialind)>1
  45. timelock.dimord = 'rpt_chan_freq_time';
  46. timelock.powspctrm = permute(subsref(this, substruct('()', {chanind, freqind, timeind, trialind})), [4 1 2 3]);
  47. else
  48. timelock.dimord = 'chan_freq_time';
  49. timelock.powspctrm = spm_squeeze(subsref(this, substruct('()', {chanind, freqind, timeind, trialind})), 3);
  50. end
  51. timelock.time = time(this, timeind);
  52. else
  53. if isequal(type(this), 'single') || length(trialind)>1
  54. timelock.dimord = 'rpt_chan_freq';
  55. timelock.powspctrm = spm_squeeze(permute(subsref(this, substruct('()', {chanind, freqind, timeind, trialind})), [4 1 2 3]), 4);
  56. else
  57. timelock.dimord = 'chan_freq';
  58. timelock.powspctrm = spm_squeeze(subsref(this, substruct('()', {chanind, freqind, timeind, trialind})), [3 4]);
  59. end
  60. end
  61. timelock.freq = frequencies(this, freqind);
  62. else
  63. error('Unknown transform type.');
  64. end
  65. if length(trialind)>1
  66. clist = condlist(this);
  67. condlabels = conditions(this, trialind);
  68. timelock.trialinfo = 0*trialind;
  69. for k = 1:numel(clist)
  70. fprintf('mapping condition label "%s" to condition code %d\n', clist{k}, k);
  71. sel = strcmp(clist{k}, condlabels);
  72. timelock.trialinfo(sel) = k;
  73. end
  74. end
  75. if ~isempty(sensors(this, 'MEG'))
  76. timelock.grad = sensors(this, 'MEG');
  77. end
  78. if ~isempty(sensors(this, 'EEG'))
  79. timelock.elec = sensors(this, 'EEG');
  80. end