spm_ndgrid.m 1000 B

1234567891011121314151617181920212223242526272829303132333435
  1. function [X,s] = spm_ndgrid(x)
  2. % returns a matrix of grid points in the domain specified by x
  3. % FORMAT [X,x] = spm_ndgrid(x)
  4. %
  5. % x{i): cell array of vectors specifying support or;
  6. % x(i): vector of bin numbers in the range [-1 1]
  7. %
  8. % x{i): cell array of vectors specifying support or;
  9. % X: (n x m) coordinates of n points in m-D space
  10. %__________________________________________________________________________
  11. % Copyright (C) 2005 Wellcome Trust Centre for Neuroimaging
  12. % Karl Friston
  13. % $Id: spm_ndgrid.m 2032 2008-09-02 18:31:16Z karl $
  14. % event-space: domain s
  15. %--------------------------------------------------------------------------
  16. n = length(x);
  17. if iscell(x)
  18. s = x;
  19. else
  20. for i = 1:n
  21. s{i} = linspace(-1,1,x(i));
  22. end
  23. end
  24. % create X - coordinates of evaluation grid
  25. %---------------------------------------------------------------------------
  26. for i = 1:n
  27. q = 1;
  28. for j = 1:n
  29. q = spm_kron(s{j}(:).^(i == j),q);
  30. end
  31. X(:,i) = q;
  32. end