# MATLAB deg2rad Function

This tutorial will discuss converting angles from degrees to radians using MATLAB’s `deg2rad()`

function.

## the MATLAB `deg2rad()`

Function

We can use MATLAB’s `deg2rad()`

function to convert the angle units from degrees to radians. The syntax of the `deg2rad()`

function is given below.

```
rad = deg2rad(deg)
```

The above syntax will convert the angle stored in the variable `deg`

to radians and save it in the `rad`

variable. The input variable `deg`

can be a scalar, vector, matrix, or array of any dimension.

The output variable will have the same data type and size as the input variable. For example, if the input angle is a scalar, the output angle will also be a scalar.

Suppose the input variable is a matrix, array, or vector; the `deg2rad()`

function will convert all the matrix, array, or vector elements to radians. For example, let’s convert an angle in degrees to radians using the `deg2rad()`

function.

See the code below.

```
clc
clear
rad = deg2rad(90)
```

Output:

```
rad =
1.5708
```

In the above code, we converted the 90-degree angle to radians. The `deg2rad()`

function is introduced in Matlab version R2015b, and there is another function, `degtorad()`

, which is introduced in Matlab version R2009b, and it was used to convert the angle from degree to radians.

MATLAB does not recommend the `degtorad()`

function if we use MATLAB version R2015b or higher, but we can use it if the version of Matlab is below R2015b. The `degtorad()`

also depends on the map toolbox, and we cannot use the function if we don’t have the map toolbox.

Another difference is that the `degtorad()`

function accepts inputs in integer data types, and the `deg2rad()`

function accepts inputs in single and double data types. We can convert an integer data type to single or double using Matlab’s `single()`

and `double()`

functions.

If the input is in an integer data type like `uint8`

, we have to convert the input to a single or double data type before using the `deg2rad()`

function to convert the angle from degree to radians. If we used the `degtorad()`

function in the above example, the output of the above example would remain the same.