/MatlabCode/branches/Greg's Branch/Analysis/mkbasis.m

http://horwitzlab.googlecode.com/ · MATLAB · 54 lines · 27 code · 4 blank · 23 comment · 4 complexity · 85499e780aeb642c6078daab2db8108d MD5 · raw file

  1. function [out] = mkbasis(in,opt)
  2. %
  3. % Called by EeroStuff.m This function will create a
  4. % basis set for use in visualizing and analysizing the
  5. % response of the neuron as a function of projections
  6. % onto 2-D linear subspaces.
  7. %
  8. % INPUT
  9. % in: A column matrix of vectors that span the subspace
  10. % of interest.
  11. % opt: Option flag that specifies operations to be
  12. % performed on the input vectors
  13. % 'RotOrtho': Rotate columns [2:end] so that
  14. % they are orthogonal to column 1
  15. % 'ProjOrtho': If called with a three column
  16. % input matrix - returns the linear combination
  17. % of the 2nd and 3rd input columns that is orthogonal
  18. % to the first input column.
  19. %
  20. % If the 'opt' field is left blank, we just scale
  21. % the columns of 'in' to unit norm.
  22. %
  23. ndim = size(in,1);
  24. nbasisvects = size(in,2);
  25. if (nargin < 2)
  26. opt = 'Nothing';
  27. end
  28. % First, rescalling vectors to unit length
  29. normfactors = sqrt(sum(in.^2));
  30. in = in./repmat(normfactors, ndim,1);
  31. in(:,normfactors == 0) = 0;
  32. if (strcmp(opt,'ProjOrtho'))
  33. if (nbasisvects == 3)
  34. proj = [in(:,1)'*in(:,2); in(:,1)'*in(:,3)];
  35. proj = rotateXY(proj'./norm(proj),pi/2);
  36. in = proj(1)*in(:,2)+proj(2)*in(:,3);
  37. else
  38. error('Only three columns allowed for ProjOrtho');
  39. end
  40. end
  41. if (strcmp(opt,'RotOrtho'))
  42. projs = in(:,1)'*in(:,[2:end]);
  43. in(:,[2:end]) = in(:,[2:end])-repmat(projs,ndim,1).*...
  44. repmat(in(:,1),1,nbasisvects-1);
  45. end
  46. % Rescalling vectors to unit length again
  47. normfactors = sqrt(sum(in.^2));
  48. out = in./repmat(normfactors, ndim,1);
  49. out(:,normfactors == 0) = 0;