ZeroCenteredBounds.m 825 B

123456789101112131415161718192021222324252627
  1. function [ bounds ] = ZeroCenteredBounds( data, clipPrctileRange )
  2. % ZEROCENTEREDINTERVAL returns a zero centered interval that surrounds
  3. % input data. useful for determining the color interval for imagesc map
  4. % plotting. to set minVal and maxVal to true min and max, use
  5. % clipPrctileRange = [0 100].
  6. minVal = prctile( data(:), clipPrctileRange(1) );
  7. maxVal = prctile( data(:), clipPrctileRange(2) );
  8. if isnan( minVal ) || isnan( maxVal )
  9. bounds = [-1 1];
  10. else
  11. if sign( minVal ) == sign( maxVal )
  12. if sign( minVal ) < 0
  13. bounds = [minVal -minVal];
  14. elseif sign( minVal ) > 0
  15. bounds = [-maxVal maxVal];
  16. else
  17. bounds = [-1 1];
  18. end
  19. else
  20. scaleVal = max( abs( minVal ), abs( maxVal ) );
  21. bounds = [-scaleVal scaleVal];
  22. end
  23. end
  24. end