Open In App

Normalize Data in MATLAB

Improve
Improve
Like Article
Like
Save
Share
Report

Data Normalization is a technique in statistical mathematics that converts the entire data into a specified range or scale or normalizes it using different methods such as by computing its z-score. There is no specific definition of normalization but, it has various meanings depending on the user’s needs.

In this article, we will discuss how to normalize data in MATLAB with various options available. It is assumed that the reader has knowledge of Normalization as explaining the same is out of this article’s scope. Let us now see how Normalization is done in MATLAB.

Data Normalization in MATLAB:

MATLAB provides the normalize() function to normalize data. By default, it normalizes the data by calculating the vector-wise z-score of the data with center 0 and standard deviation 1. 

Syntax:

N = normalize(data)

Where data could be

  • A vector
  • A Matrix
  • A Multidimensional array
  • A table

Now let us understand the same with examples.

Let us normalize the data in a vector.

Example 1:

Matlab




% MATLAB code for data normalization
vec = 1:7;    
  
% Function for normalize
Nvec = normalize(vec);


Output:

 

When a matrix is passed to the normalize() function, it normalizes all of its elements column-wise.

Example 2:

Matlab




% MATLAB code for square matrix normalizing
% Creating a magic square matrix
mat = magic(3);    
  
% Normalizing the matrix
Nvec = normalize(mat);


Output:

 

Normalizing a matrix along a specific dimension.

Example 3:

Matlab




% MATLAB code for data normalizing 
mat = magic(3);
  
% Normalizing along 1st dimension
Nvec1 = normalize(mat,1)
  
% Normalizing along 2nd dimension
Nvec2 = normalize(mat,1)


Output:

 

We can also normalize a vector by scaling it by its standard deviation.

Example 4:

Matlab




% MATLAB code for data Scale
vec = 1:7;
  
% Normalization by scaling
% by standard deviation
Nvec = normalize(vec,'scale');


Output:

 

MATLAB also provides an option to scale data in a range of [0,1]. This can be done as follows:

Example 5:

Matlab




% MATLAB code for normalize data with range
vec = 1:7;
Nvec = normalize(vec,'range');


Output:

 



Last Updated : 27 Oct, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads