## Introduction to Ceil Matlab

In this article, we will learn how the Ceil function works in MATLAB. Ceil function finds its utility in Mathematical problems involving decimal values. Ceil function helps in rounding off these decimal values to the nearest integer. As we will move forward in the article, we will learn how this is achieved for different types of scenarios.

### Ceil Function

The ceil function or ceiling function (also commonly called ‘least integer function**’**) for any real number gives the smallest integer which is greater than the number itself. Now the question is there can be the infinite number of integers that are greater than the given real number. So, how does Ceil function work?

As we can interpret from the definition above, the Ceil function will choose the ‘SMALLEST’ of all those integers. Which clearly will be the immediate next integer. The output of ceil function can be the same as the input if the real number is actually an integer and not a decimal value.

#### Example

**Real number = 2.134:** If this number is provided as input to the Ceil function, the output will be ‘3’, which is the immediate integer greater than 2.134

### What is the Syntax of Ceil Function in MATLAB?

Let us now understand the Syntax of Ceil function in MATLAB

**A = ceil(X):**This syntax is used when we have a number as input**A = ceil (time):**This syntax is used when we have TIME as our input

ceil(X) function in MATLAB also helps us in rounding off the complex numbers. For complex value X, the real and imaginary parts are independently rounded off.

4.5 (6,009 ratings)

View Course

### Examples to Implement Ceil Matlab

Let us now understand the use of above-mentioned functions clearly with the help of a few examples:

#### Example #1

To use the ceil function, we will first create an array of numbers:

**Syntax**

`X = [1.23 2.34 5.43 6]`

Now, this is a simple example without any other negative value or complex number.

This array of numbers is then passed as an argument to our function ‘ceil(X). This is how our input and output will look like in MATLAB console:

**Code:**

`X = [1.23 2.34 5.43 6];`

Y = ceil(X)

**Output:**

As we can see in our output, all the values are rounded off to their immediate next integer. Also notice that the value ‘6’ stays unchanged, as it is already an integer.

#### Example #2

Now let us take an example with negative values as well, and see how our function works

**Syntax**

`X = [-0.56 2.78 -4.56 -3.23]`

This array of both positive and negative numbers is then passed as an argument to our function ‘ceil(X). This is how our input and output will look like in MATLAB console:

**Code:**

`X = [-0.56 2.78 -4.56 -3.23];`

Y = ceil(X)

**Output:**

**Note:**In the above output how negative values are rounded off. ‘-4.56’ is rounded off to ‘-4’ and not ‘–5’, because ‘-4’ is the integer greater than ‘-4.56’ and falls immediately after it.

#### Example #3

In the next example, we will understand how are ceil function works for Complex values.

**Syntax**

`X = [2.9 -6.27.1; 593.1+6.2i]`

In this problem, we have a 2*3 matrix with a complex value ‘3.1 + 6.2i’.

This array of both simple and complex numbers is then passed as an argument to our function ‘ceil(X). This is how our input and output will look like in MATLAB console**:**

**Code;**

```
X = [2.9 -6.2 7.1; 5 9 3.1+6.2i]
Y = ceil(X)
```

**Output:**

As we can see in the above output, for the complex number, the real and the imaginary parts are rounded off independently.

#### Example #4

In the next example, we will understand how are ceil function works for TIME input. For this purpose, the syntax used is A = ceil (time). We will use MATLAB command to create an array of ‘time’.

**Code:**

`time = hours(5) + minutes(9:13) + seconds(1.43);`

time.Format = ‘hh:mm:ss.SS’

The above format is used to create a TIME array in MATLAB.

**Note:**That ‘minutes(9:13)’ will create 5 elements with minutes in the range 9 to 13, both values included.

**Output:**

**Code:**

`out = ceil(time)`

**Output:**

As we can clearly notice in our output, the time is rounded off to the immediate integer which is greater than the ‘seconds’ value.

### Conclusion

So, in this article, we learned how the ceil function works in MATLAB. We can use ceil function to round off both simple and complex numbers in MATLAB. As an additional feature, ceil function can also be used for rounding off TIME values.

### Recommended Articles

This is a guide to Ceil Matlab. Here we discuss an introduction to Ceil Matlab with appropriate syntax, function, and programming examples. You can also go through our other related articles to learn more –