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 Matlab Round
 

Matlab Round

Updated March 13, 2023

Matlab Round

 

 

Introduction to Matlab Round

‘Round off’ is performed in mathematics to restrict the number of significant digits. For example, the value of ‘pi’ is 3.14159265358979323, and using this entire value every time in calculations can become cumbersome and unnecessary. To avoid this, we round off the values to the required number of decimal places. This is the reason why we mostly see the value of pi as 3.14 (rounding off the value to 2 decimal places).

Watch our Demo Courses and Videos

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

In MATLAB we use ‘round’ function for the purpose of rounding off the numeric values.

Syntax:

R = round (A)

R = round (A, N)

Description:

  • R = round (A) will round off ‘A’ to the nearest integer. In the case of an array, all the elements of ‘A’ are rounded off to the nearest integer
  • R = round (A, N) will round off ‘A’ till ‘N’ digits. If N < 0, the rounding off is done to the left of the decimal

Examples of Matlab Round

Let us now understand the code of round function in MATLAB using different examples:

Example #1

In this example, we will take a 3 x 3 matrix. For our first example, we will follow the following steps:

  1. Initialize the input 3 x 3 matrix
  2. Pass the matrix as an input to the round function

Code:

A = [3.11  4.015  11.092;  -3.45  10.8  3.001;  4.981  2.012  4.1];

[Declaring the 3 x 3 input matrix]

R = round(A)

[Passing the input matrix to the round function] [Mathematically, if we round off all the elements in the above matrix, we will get the following values:

3     4      11

-3    11     3

5     2      4]

Input:

A = [3.11  4.015  11.092;  -3.45  10.8  3.001;  4.981  2.012  4.1];
R = round(A)

Output:

Matlab Round-1.1

As we can see in the output, we have obtained the rounded off values of all the elements in the matrix.

Example #2

In this example, we will take a 2 x 2 matrix. For this example, we will follow the following steps:

  1. Initialize the input 2 x 2 matrix
  2. Pass the matrix as an input to the round function

Code:

A = [1.11  0.01;  -4.45  12.803];

[Declaring the 2 x 2 input matrix]

R = round(A)

[Passing the input matrix to the round function] [Mathematically, if we round off all the elements in the above matrix, we will get the following values:

1     0

-4    13]

Input:

A = [1.11  0.01;  -4.45  12.803];
R = round(A)

Output:

Matlab Round-1.2

As we can see in the output, we have obtained the rounded off values of all the elements in the matrix. In the above 2 examples, we saw that all the values were rounded off to the nearest integers. Next, we will learn how to round off the values to the required number of decimal places.

Example #3

In this example, we will take a 2 x 2 matrix and will round off each element to 1 decimal place. i.ethere will be one digit after the decimal in the output. For this example, we will follow the following steps:

  1. Initialize the input 2 x 2 matrix
  2. Pass the matrix as the first argument to the round function
  3. Pass ‘1’ as the second argument to the round function

Code:

A = [1.1134  0.09341;  4.43415  1.8103];

[Declaring the 2 x 2 input matrix]

R = round(A, 1)

[Passing the input matrix to the round function. The second argument, ‘1’ is passed to specify the number of digits we need after the decimal point] [Mathematically, if we round off all the elements in the above matrix till 1st decimal place, we will get the following values:

1.1   0.1

4.4    1.8]

Input:

A = [1.1134  0.09341;  4.43415  1.8103];
R = round(A,1)

Output:

1.3

As we can see in the output, all the elements in the matrix are rounded off till the first decimal place]. Next, we will learn how to round off digits to the right of the decimal point

Example #4

In this example, we will take a 2 x 2 matrix and will round it off to the one-point right of the decimal place. i.e all digits to the right of ‘tens digit’ will become zero or will be rounded off. For this example, we will follow the following steps:

  1. Initialize the input 2 x 2 matrix
  2. Pass the matrix as the first argument to the round function
  3. Pass ‘-1’ as the second argument to the round function

Code:

A = [321.1134  20.09341;  34.43415  14.8103];

[Declaring the 2 x 2 input matrix]

R = round(A, -1)

[Passing the input matrix to the round function. The second argument, ‘-1’ will round off all the digits before tens place] [Mathematically, if we round off all the elements in the above matrix before tens place, we will get the following values:

320    20

30    10]

Input:

A = [321.1134  20.09341;  34.43415  14.8103];
R = round(A, -1)

Output:

1.4

As we can see in the output, all the elements in the matrix are rounded off and digits before tens place have become zero]

Conclusion

  • ‘round’ function is used in MATLAB to round off the numeric values.
  • ‘round’ by default rounds off values to the nearest integer. An argument can be passed if we need values to be rounded off till some other place.

Recommended Articles

This is a guide to Matlab Round. Here we also discuss the introduction and syntax of matlab round along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Cell to String MATLAB
  2. Matlab Import Data
  3. Matlab fopen
  4. Matlab fopen

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