spm_eeg_fixpnt.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. function data = spm_eeg_fixpnt(data, recurse)
  2. % Helper function to replace pos by pnt
  3. %__________________________________________________________________________
  4. % Copyright (C) 2016 Wellcome Trust Centre for Neuroimaging
  5. % Vladimir Litvak
  6. % $Id: spm_eeg_fixpnt.m 6683 2016-01-15 16:15:32Z guillaume $
  7. if nargin==1
  8. recurse = 1;
  9. end
  10. if ~isa(data, 'struct')
  11. return;
  12. end
  13. if numel(data)>1
  14. % loop over all individual elements
  15. clear tmp
  16. for i=1:numel(data)
  17. % this is to prevent an "Subscripted assignment between dissimilar structures" error
  18. tmp(i) = spm_eeg_fixpnt(data(i));
  19. end
  20. data = tmp;
  21. clear tmp
  22. return
  23. end
  24. % replace pos by pnt
  25. if isfield(data, 'pos')
  26. data.pnt = data.pos;
  27. data = rmfield(data, 'pos');
  28. end
  29. if recurse<3
  30. % recurse into substructures, not too deep
  31. fn = fieldnames(data);
  32. fn = setdiff(fn, {'cfg'}); % don't recurse into the cfg structure
  33. for i=1:length(fn)
  34. if isstruct(data.(fn{i}))
  35. data.(fn{i}) = spm_eeg_fixpnt(data.(fn{i}), recurse+1);
  36. end
  37. end
  38. end