7. Display options

7. Display options - Display Options Controlling the...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
©2009 by L. Lagerstrom Display Options • Controlling the display • Display formats: format short, format long, etc. • Going for total control: using fprintf • Specifying the number width and line breaks • Displaying exponential notation • Displaying multiple variable values • Tips and comments re. fprintf
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
©2009 by L. Lagerstrom Controlling the Display So far we have seen two ways of displaying results in Matlab: 1. Leave off the semi-colon at the end of an assignment statement: Matlab will display the name of the variable and its value. 2. Use the disp function to display either a string or a numeric value. In both cases Matlab will display the numeric result according to a certain display format. We can control the display format by using the format command (next slide).
Background image of page 2
©2009 by L. Lagerstrom Display Formats Matlab's default display format (and the one we've been assuming in our examples) is "format short," standing for a short, fixed point display. In this format: 1. Integer values are displayed as is if they are 9 digits or less, or in scientific notation for 10 digits or more. 2. Numbers with a decimal part are displayed with four digits to the right of the decimal point and up to three digits to the left of the decimal point. If more than three digits are required to the left of the decimal point, then the number is displayed in scientific notation. 3. If necessary, Matlab rounds the number, but for display purposes only; the actual stored value retains all its decimal places so that no precision is lost if the value is used in later calculations.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Matlab code Command window display ©2009 by L. Lagerstrom Format Short Examples %Though "format short" is the default %Matlab display format, we can also %make sure it is set by typing: format short %Some examples: a = 394 b = 394.7 c = 394.79428 d = 2394 e = 2394.79 disp(' ') %Blank line x = 610/17 y = 6100/17 z = 61000/17 %Using disp gives similar results: disp(' ') %Blank line disp(x) disp(y) disp(z) a = 394 b = 394.7000 c = 394.7943 d = 2394 e = 2.3948e+003 x = 35.8824 y = 358.8235 z = 3.5882e+003 35.8824 358.8235 3.5882e+003
Background image of page 4
Matlab code Command window display ©2009 by L. Lagerstrom Format Long Examples %If we want more decimal places, we %can use a fixed point, long format, %which is like format short but %displays not 4 but 15 decimal %places (usually more than we want). format long %Set the format a = 394 b = 394.7 c = 394.79428 d = 2394 e = 2394.79 disp(' ') %Blank line x = 610/17 y = 6100/17 z = 61000/17 disp(' ') %Blank line disp(x) disp(y) disp(z) a = 394 b = 3.947000000000000e+002 c = 3.947942800000000e+002 d = 2394 e = 2.394790000000000e+003 x = 35.882352941176471 y = 3.588235294117647e+002 z = 3.588235294117647e+003 35.882352941176471 3.588235294117647e+002 3.588235294117647e+003
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Matlab code Command window display ©2009 by L. Lagerstrom Format Short Exponential Examples %We can specify exponential (scien- %tific, or "floating point") notation %for non-integer results using "for-
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

7. Display options - Display Options Controlling the...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online