fixpnt.m 840 B

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