## Introduction to MATLAB Normalize

MATLAB is a programming environment which is interactive and is used in scientific computing. It is extensively used in a lot of technical fields where problem solving, data analysis, algorithm development and experimentation is required. Software which are discipline specific are extensively written using MATLAB. MATLAB provides us with ‘normalize function’ for the purpose of performing normalization of vectors. We perform normalization if we need our data to be in a range something like [-1 to 1]. In other words, Normalization is linear transformation of our data and is necessary at times when limits are imposed on data because of floating point arithmetic.

**Syntax:**

`A = normalize (X)`

**Description:**

A = normalize (X) will return the z-score of data in X (standard deviation is 1 ¢er is 0).

In case the input ‘X’ is a vector, the normalize function will work on the entire input. If input ‘X’ is multidimensional array, the normalize function will operate along the 1^{st} dimension of the array, whose size is not equal to 1.

### Examples of MATLAB Normalize

Given below are the examples mentioned:

#### Example #1

Here we will see how the code for normalizing a 3 X 3 array looks like.

**Code:**

X = [3 4 6, 7 1 9, 0 2 2] [Creating the input 3 X 3 array]

A = normalize (X)

[Using the normalize function and passing the input array]**Input:**

4.5 (6,009 ratings)

View Course

```
X = [3 4 6, 7 1 9, 0 2 2]
A = normalize (X)
```

**Output:**

#### Example #2

Now what if all the elements of the array are same. Like in identity matrix, where all the elements are 1.

**Input:**

```
X = [1 1 1, 1 1 1, 1 1 1]
A = normalize (X)
```

**Output:**

There are a few methods which we can pass as an argument to the normalize function in order to get the output as per our requirement.

Here are the 3 main methods which we can pass as the argument:

**Scale:**This method is used to normalize the input using standard deviation.**Range:**This method normalizes the input in the range [0 to 1].**Center:**This method will normalize the data to have ‘0’ as mean.

**a. Scale**

**Code:**

X = 1 : 7;

[Initializing the input vector]A = normalize (X, ‘scale’)

[Calling the normalize function and passing the ‘scale’ method]**Input:**

`X = 1 : 7;`

A = normalize (X, 'scale')

**Output:**

**b. Range**

**Code:**

X = 1 : 7;

[Initializing the input vector]A = normalize (X, ‘range’)

[Calling the normalize function and passing the ‘range’ method]**Input:**

`X = 1 : 7;`

A = normalize (X, 'range')

**Output:**

As we can see, our output is normalized in the range [0, 1].

**3. Center**

**Code:**

X = 1 : 7;

[Initializing the input vector]A = normalize (X, ‘center’)

[Calling the normalize function and passing the ‘center’ method]**Input:**

`X = 1 : 7;`

A = normalize (X, 'center')

**Output:**

As we can see, our output is normalized with ‘0’ as mean.

#### Example #3

‘Normalize function’ can also be used to normalize the values of an attribute in a table. For getting normalized values in this case, we need to pass a few more arguments.

In this example, we will create a table with 5 Indian cities and their respective temperatures. Finally, we will normalize the temperature w.r.t. the maximum temperature in the table.

**Code: **

CityName = {‘Delhi’; ‘Mumbai’; ‘Bengaluru’; ‘Chennai’; ‘Hyderabad’};

[Defining the column 1 of the table]Temperature = [43; 38; 27; 40; 41];

[Defining the column 2 of the table]Tab = table (CityName, Temperature)

[Creating the table]NormalizedTemp = normalize (Tab, ‘norm’, Inf, ‘DataVariables’, ‘Temperature’)

[Using the normalize function for the table ‘Tab’. Note that, here we have passed 3 new arguments: ‘Inf’, ‘DataVariables’, ‘Temperature’, this will tell MATLAB to normalize the ‘temperature’ attribute w.r.t the maximum temperature in the column].**Input:**

`CityName = {'Delhi'; 'Mumbai'; 'Bengaluru'; 'Chennai'; 'Hyderabad'};`

Temperature = [43; 38; 27; 40; 41];

Tab = table (CityName, Temperature)

NormalizedTemp = normalize (Tab, 'norm', Inf, 'DataVariables', 'Temperature')

**Output:**

As we can see, our column values are normalized with highest value being 1.

### Conclusion

MATLAB provides us with ‘normalize’ function to normalize the vectors or arrays. We can also use the methods like ‘range’, ‘scale’, ‘center’ in the argument depending upon the type of output we expect.

### Recommended Articles

This is a guide to MATLAB Normalize. Here we discuss the introduction to MATLAB Normalize along with programming examples respectively. You may also have a look at the following articles to learn more –