subsref.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function varargout = subsref(this,subs)
  2. % Subscript referencing for GIfTI objects
  3. %__________________________________________________________________________
  4. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  5. % Guillaume Flandin
  6. % $Id: subsref.m 7291 2018-04-12 08:43:08Z guillaume $
  7. if length(this) > 1 && ~strcmp(subs(1).type,'()')
  8. warning('Not implemented.');
  9. for i=1:numel(this)
  10. varargout{i} = subsref(this(i),subs);
  11. end
  12. return;
  13. end
  14. switch subs(1).type
  15. case '.'
  16. [i,j] = isintent(this,subs(1).subs);
  17. if isempty(i)
  18. if strcmp(subs(1).subs,'private')
  19. varargout{1} = builtin('struct',this);
  20. else
  21. error('Reference to non-existent field ''%s''.',subs(1).subs);
  22. end
  23. else
  24. if strcmp(subs(1).subs,'mat')
  25. varargout{1} = this.data{j}.space.MatrixData;
  26. elseif strcmp(subs(1).subs,'labels')
  27. varargout{1} = this.label;
  28. else
  29. if length(j) == 1
  30. varargout{1} = this.data{j}.data;
  31. else
  32. a = [this.data{j}];
  33. try
  34. varargout{1} = [a.data];
  35. catch
  36. error('Data arrays are of different sizes.');
  37. end
  38. end
  39. end
  40. end
  41. if strcmp(subs(1).subs,'faces') || strcmp(subs(1).subs,'indices')
  42. varargout{1} = varargout{1}() + 1; % indices start at 1
  43. end
  44. if length(subs) > 1
  45. varargout{1} = subsref(varargout{1},subs(2:end));
  46. end
  47. case '{}'
  48. error('Cell contents reference from a non-cell array object.');
  49. case '()'
  50. if length(subs) == 1
  51. varargout{1} = builtin('subsref',this,subs(1));
  52. else
  53. varargout{1} = subsref(builtin('subsref',this,subs(1)),subs(2:end));
  54. end
  55. otherwise
  56. error('This should not happen.');
  57. end