spm_dcm_voi.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. function DCM = spm_dcm_voi(DCM,VOIs)
  2. % Insert new regions into a DCM
  3. % FORMAT DCM = spm_dcm_voi(DCM,VOIs)
  4. %
  5. % DCM - DCM structure or its filename
  6. % VOIs - cell array of new VOI filenames
  7. % eg. {'VOI_V1','VOI_V5','VOI_SPC'}
  8. %
  9. % The TR, TE and delays are assumed to be the same as before.
  10. %
  11. % This function can be used, for example, to replace subject X's data by
  12. % subject Y's. The model can then be re-estimated without having to go
  13. % through model specification again.
  14. %__________________________________________________________________________
  15. % Copyright (C) 2002-2015 Wellcome Trust Centre for Neuroimaging
  16. % Will Penny
  17. % $Id: spm_dcm_voi.m 6400 2015-04-07 18:19:20Z guillaume $
  18. %-Get input arguments
  19. %--------------------------------------------------------------------------
  20. if ~nargin
  21. [DCM, sts] = spm_select(1,'^DCM.*\.mat$','select DCM_???.mat');
  22. if ~sts, return; end
  23. end
  24. if ~isstruct(DCM)
  25. DCMfile = DCM;
  26. load(DCM);
  27. end
  28. n = DCM.n ;
  29. if nargin < 2
  30. [VOIs, sts] = spm_select(n,'^VOI.*\.mat$','select VOIs');
  31. if ~sts, return; end
  32. end
  33. VOIs = cellstr(VOIs);
  34. %-Check we have matching number of regions
  35. %--------------------------------------------------------------------------
  36. if n ~= numel(VOIs)
  37. error('DCM contains %d regions while %d VOI files were given.',...
  38. n, numel(VOIs));
  39. end
  40. %-Replace relevant fields in DCM with xY
  41. %--------------------------------------------------------------------------
  42. DCM.xY = [];
  43. DCM.Y.y = [];
  44. for i=1:n
  45. load(VOIs{i});
  46. DCM.Y.y(:,i) = xY.u;
  47. DCM.Y.name{i} = xY.name;
  48. DCM.xY = spm_cat_struct(DCM.xY,xY);
  49. end
  50. DCM.v = size(xY.u,1);
  51. DCM.Y.X0 = xY.X0;
  52. DCM.Y.Q = spm_Ce(ones(1,n)*DCM.v);
  53. %-Save (overwrite) new DCM file
  54. %--------------------------------------------------------------------------
  55. if exist('DCMfile','var')
  56. save(DCMfile, 'DCM', spm_get_defaults('mat.format'));
  57. end