Home > GLMdenoise > utilities > normalizemax.m

normalizemax

PURPOSE ^

function f = normalizemax(m,dim)

SYNOPSIS ^

function f = normalizemax(m,dim)

DESCRIPTION ^

 function f = normalizemax(m,dim)

 <m> is a matrix
 <dim> (optional) is the dimension of <m> to operate upon.
   default to 2 if <m> is a row vector and to 1 otherwise.
   special case is 0 which means operate globally.

 divide <m> by the max value along some dimension (or globally).

 example:
 isequal(normalizemax([1 2 3]),[1/3 2/3 1])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f = normalizemax(m,dim)
0002 
0003 % function f = normalizemax(m,dim)
0004 %
0005 % <m> is a matrix
0006 % <dim> (optional) is the dimension of <m> to operate upon.
0007 %   default to 2 if <m> is a row vector and to 1 otherwise.
0008 %   special case is 0 which means operate globally.
0009 %
0010 % divide <m> by the max value along some dimension (or globally).
0011 %
0012 % example:
0013 % isequal(normalizemax([1 2 3]),[1/3 2/3 1])
0014 
0015 % input
0016 if ~exist('dim','var') || isempty(dim)
0017   dim = choose(isrowvector(m),2,1);
0018 end
0019 
0020 % do it
0021 if dim==0
0022   f = m / max(m(:));
0023 else
0024   f = bsxfun(@rdivide,m,max(m,[],dim));
0025 end

Generated on Fri 01-Aug-2014 12:03:17 by m2html © 2005