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 format long Matlab
 

format long Matlab

Priya Pedamkar
Article byPriya Pedamkar

Updated May 19, 2023

format long Matlab

 

 

Introduction to format long Matlab

The format functions are used in various computer-based languages to get the output in the desired format. In the case of Matlab, the format function is used to set the result obtained in the command window to the desired format. Format function has various types or styles like short, long, hex, etc.

Watch our Demo Courses and Videos

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

Syntax:

format type

format

Description:

  • format type is used to change the display format of output in Matlab’s Command Window and set it to the display format given by ‘type’
  • If we do not pass any ‘type’, then by default, the format function will set the display format of output to ‘short’ type.

The long type has the following variations:

  • long: 15 digits are displayed after the decimal point.
  • longEng: 15 digits and an exponential, which is a multiple of three.
  • longE: 15 digits are displayed in scientific notation.
  • longG: It displays the output in either scientific notation or in fixed decimal format, depending upon which format is more compact.

Examples of format long Matlab

Given below are the examples mentioned:

Example #1

In this example, we will take the division of 2 integers and will use the format function to get the output in long format.

We will follow the following 2 steps:

  • Use format function with type ‘long’.
  • Perform division of 2 integers.

Syntax:

format long

[Passing the type as ‘long’ to the format function]

X = 1/3

[Initializing a variable and passing division of 2 integers into it] [Mathematically, the value of1/3 is 0.3333….. which goes on till infinity. Now since we have used long as our type, our output will be restricted to 15 digits]

Code:

format long
X = 1/3

Output:

format long Matlab 1

As we can see, we have obtained our output in 15 digits because we used ‘long’ as a type for the format function.

Example #2

Let us now see the code to use the format function for longEng type in Matlab.

In this example, we will take the same example as we used above for better understanding.

We will follow the following 2 steps:

  • Use format function with type longEng.
  • Perform division of 2 integers.

Syntax:

format longEng

[Passing the type as ‘longEng’ to the format function]

X = 1/3

[Initializing a variable and passing division of 2 integers into it] [Mathematically, the 1/3 is 0.3333….. which goes on till infinity. Since we have used longEng as our type, our output will be restricted to 15 digits, 3 before decimal, and 12 after that. Also, we will get an exponential which is a multiple of three]

Code:

format longEng
X = 1/3

Output:

format long Matlab 2

As we can see, we have obtained our output with 3 digits before and 12 digits after decimal notation because we used ‘longEng’ as a type for the format function.

Example #3

Let us now see the code to use the format function for longE type in Matlab.

In this example, we will take an array of random numbers and use longE type to format the output.

We will follow the following 2 steps:

  • Pass the type as ‘longE’ to the format function.
  • Create the input array of random numbers.

Syntax:

format longE

[Passing the type as ‘longE’ to the format function]

A = rand (3)

[Creating the array of random numbers] [longE will give us the output in scientific notation and with 15 digits after decimal]

Code:

format longE
A = rand (3)

Output:

array of random numbers

As we can see, we have obtained our output in scientific notation and 15 digits after decimal because we used ‘longE’ as a type for the format function.

Example #4

Let us now see the code to use the format function for longG type in Matlab.

In this example, we will take the same array as used above and will use longG type to format the output.

We will follow the following 2 steps:

  • Pass the type as ‘longG’ to the format function.
  • Create the input array of random numbers.

Syntax:

format longG

[Passing the type as ‘longG’ to the format function]

A = rand (3)

[Creating the array of random numbers] [longG will display the output in either scientific notation or in fixed decimal format, depending upon which format is more compact]

Code:

format longG
A = rand (3)

Output:

Create the input array of random numbers

Conclusion

To get the output in the format we want, we can utilise Matlab’s format function. If we anticipate that our output will include around 15 digits, we can utilise a long format.

Recommended Articles

We hope that this EDUCBA information on “format long Matlab” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. Factorial in Matlab
  2. Matlab rref
  3. Matlab Figure
  4. MATLAB cylinder()

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
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

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?

🚀 Limited Time Offer! - 🎁 ENROLL NOW