Search the courses, subjects, tracks, games and features, or jump straight to a page.
Learn it your way
A short class with Sarah and her students. The other ways are under More.
Sign up free to listen. Transcripts are free to read.
Today, we're going to dive into how floating point numbers are displayed in MATLAB. Can anyone tell me why the display format might be important when working with numbers?
I think it’s important because different formats can help us see more or less detail of the numbers we’re working with.
Exactly! Display formats impact how we interpret and utilize numerical results. In MATLAB, by default, numbers are displayed with four decimal places. Let's start with the command 'format short.'
So, what happens if we want to see more decimal places?
Good question! You can use 'format long' to display all 15 digits of a floating point number. Let's try it out with a simple example.
Are there ways to switch back to the original format?
Yes, using 'format short' will revert it back. Always remember to choose the format that suits your needs for clarity.
In summary, remembering the commands 'format short' and 'format long' will enhance your ability to control numeric outputs in MATLAB.
Let's explore practical examples using 'format short' and 'format long' for the same variable. How confident do you feel entering these commands?
I’m ready to try it out!
Great! First, let’s set a variable x. Input ‘x = -163.6667’ and then display it with 'format short'.
I did it! It shows -163.6667.
Now, switch to 'format long' and check x again. What do you see?
Now it shows a longer number: -1.636666666666667e+002!
Excellent observation! This highlights how MATLAB can handle precision. Remember, adding a semicolon at the end suppresses the output during long calculations.
To summarize, controlling how MATLAB displays numbers is crucial for clarity in your work.
Shorter decimals, shorter sights, long in numbers gives more insights.
Imagine a scientist working with lab data. They find that using 'format short' makes results less clear, so they switch to 'format long' to capture every detail of the measurements, ensuring accuracy.
Remember 'SIMPLE' - Short for Insightful Measurement Precision Long Exceeds.
'SPL' - Short format: Precision Limited, Long format: Precision Long.
Term
format short
Click to flip
Term
format long
Click to flip
This section explains how to control the display format of floating point numbers in MATLAB, showcasing different formatting options to represent numerical results.
In this section, we explore how MATLAB handles the display of floating point numbers and how users can modify the format to show more or fewer digits. Specific commands such as 'format short' and 'format long' are introduced, along with examples demonstrating their effects on numerical output.
This section delves into how MATLAB, by default, displays floating point numbers with a precision of four decimal places (e.g., 163.6667). However, it performs calculations using double precision, which can extend to 15 digits.
>> format short
>> x = -163.6667
This results in:
x = -163.6667
>> format long
>> x = -163.6667
This results in:
x = -1.636666666666667e+002
To revert to the original settings, users can enter:
>> format short
This command ensures that outputs return to the initial presentation style.
It's crucial to note that if commands yield extensive output, utilizing a semicolon (;) at the end of commands will suppress the display of results, allowing cleaner command execution while still being able to query variable values later.