EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Ceil Matlab
 

Ceil Matlab

Priya Pedamkar
Article byPriya Pedamkar

Updated February 27, 2023

Ceil Matlab

 

 

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.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

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.

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:

Ceil Matlab - 1

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:

Ceil Matlab - 2

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:

2*3 matrix

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:

TIME input

Code:

out = ceil(time)

Output:

Ceil Matlab - 5

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 –

  1. Size Function in MATLAB
  2. Matlab stem()
  3. Filter Function in Matlab
  4. Matlab Cell Array

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW