Normalize cols

From QETLAB
Jump to: navigation, search
normalize_cols
Scales the columns of a matrix to have norm 1

Other toolboxes required none
Function category Helper functions
This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function.

normalize_cols is a function that scales each column of a matrix so that it has norm 1. That is, each column of the matrix is divided by its norm.

Syntax

  • Y = normalize_cols(X)

Argument descriptions

  • X: A matrix to have its columns normalized.

Examples

>> X = [1 0 1;0 2 1i;0 0 -1;0 0 -1i]
 
X =
 
   1.0000                  0             1.0000          
        0             2.0000                  0 + 1.0000i
        0                  0            -1.0000          
        0                  0                  0 - 1.0000i
 
>> normalize_cols(X)
 
ans =
 
   1.0000                  0             0.5000          
        0             1.0000                  0 + 0.5000i
        0                  0            -0.5000          
        0                  0                  0 - 0.5000i

Source code

Click on "expand" to the right to view the MATLAB source code for this function.

  1. %%  NORMALIZE_COLS    Scales the columns of a matrix to have norm 1
  2. %   This function has one required argument:
  3. %     X: a matrix
  4. %
  5. %   Y = normalize_cols(X) is the same as X, except each of its columns has
  6. %   been divided by its length.
  7. %
  8. %   URL: http://www.qetlab.com/normalize_cols
  9.  
  10. %   requires: nothing
  11. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  12. %   package: QETLAB
  13. %   last updated: January 2, 2013
  14.  
  15. function Y = normalize_cols(X)
  16.  
  17. Y = X./repmat(sqrt(sum(abs(X).^2,1)),size(X,1),1);