normalize.m 748 B

1234567891011121314151617181920212223
  1. function Mnormal=normalize(M,Mbase,MD)
  2. %MD is the type of normalization.
  3. % 0 = Z-score >>(X-mean)/SD
  4. % 1 = normalized to response max
  5. % 2 = Baseline substracted
  6. % 3 = normalized by SD only >> X/SD
  7. %Added April 2012 to handle vectors
  8. if size(M,2)==1, M=M'; Mbase=Mbase'; end
  9. Mnormal=zeros(size(M));
  10. for k=1:size(M,1)
  11. if MD==0
  12. Mnormal(k,:)=(M(k,:)-nanmean(Mbase(k,:)))/nanstd(Mbase(k,:)); % Zscore
  13. elseif MD==1
  14. Tmp=M(k,:)-nanmean(Mbase(k,:));
  15. Mnormal(k,:)=Tmp/max(abs(Tmp));% mean corrected normalized to RESPONSE MAX
  16. elseif MD==2
  17. Mnormal(k,:)=(M(k,:)-nanmean(Mbase(k,:)));
  18. elseif MD==3
  19. Mnormal(k,:)=M(k,:)/nanstd(Mbase(k,:)); % Zscore no demean
  20. end
  21. end