sconfounds.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function res = sconfounds(this, newsconfounds, append)
  2. % Method for getting/setting spatial confounds
  3. % FORMAT res = sconfounds(this, newsconfounds)
  4. % _______________________________________________________________________
  5. % Copyright (C) 2015 Wellcome Trust Centre for Neuroimaging
  6. % Vladimir Litvak
  7. % $Id: sconfounds.m 6437 2015-05-14 12:27:21Z vladimir $
  8. if nargin >= 2
  9. meegind = indchantype(this, 'MEEG');
  10. [sel1, sel2] = match_str(chanlabels(this, meegind), newsconfounds.label);
  11. sel1 = meegind(sel1);
  12. if length(sel1)<length(meegind)
  13. error('The spatial confounds do not match the MEEG channels.');
  14. end
  15. if any(newsconfounds.bad(sel2)) && ~all(badchannels(this, sel1(find(newsconfounds.bad(sel2)))))
  16. warning('Setting additional channels to bad to match spatial confounds.');
  17. this = badchannels(this, find(newsconfounds.bad(sel2)), 1);
  18. end
  19. newsconfounds.label = newsconfounds.label(sel2);
  20. newsconfounds.coeff = newsconfounds.coeff(sel2, :);
  21. newsconfounds.bad = newsconfounds.bad(sel2);
  22. if nargin == 3 && isfield(this.other, 'sconfounds')
  23. oldsconfounds = this.other.sconfounds;
  24. if ~isequal(newsconfounds.label, oldsconfounds.label)
  25. error('New confounds incompatible with old. Cannot append.');
  26. end
  27. newsconfounds.coeff = [oldsconfounds.coeff newsconfounds.coeff];
  28. end
  29. this.other(1).sconfounds = newsconfounds;
  30. res = this;
  31. else
  32. chanind = indchantype(this, 'MEEG', 'GOOD');
  33. if ~isfield(this, 'sconfounds')
  34. res = zeros(length(chanind), 1);
  35. return;
  36. end
  37. [sel1, sel2] = match_str(chanlabels(this, chanind), this.other.sconfounds.label);
  38. if any(this.other.sconfounds.bad(sel2))
  39. error(['Channels ' sprintf('%s ', this.other.sconfounds.label{sel2}) ' should be set to bad.']);
  40. end
  41. res = this.other.sconfounds.coeff(sel2, :);
  42. end