spm_squeeze.m 635 B

12345678910111213141516171819202122232425
  1. function B = spm_squeeze(A, dim)
  2. % version of squeeze with the possibility to select the dimensions to remove
  3. % FORMAT B = spm_squeeze(A, dim)
  4. %
  5. %__________________________________________________________________________
  6. % Copyright (C) 2010 Wellcome Trust Centre for Neuroimaging
  7. % Vladimir Litvak
  8. % $Id: spm_squeeze.m 5794 2013-12-09 12:41:52Z vladimir $
  9. if nargin == 1
  10. B = squeeze(A);
  11. else
  12. siz = size(A);
  13. dim = intersect(dim, find(siz == 1));
  14. if ~isempty(dim)
  15. siz(dim) = [];
  16. if size(siz) == 1
  17. siz = [siz 1];
  18. end
  19. B = reshape(A, siz);
  20. else
  21. B = A;
  22. end
  23. end