7p. Display options _printable_

# 7p. Display options _printable_ - Display Options...

This preview shows pages 1–3. Sign up to view the full content.

1 ©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 ©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). ©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. 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

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

View Full Document
2 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 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-
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

### Page1 / 5

7p. Display options _printable_ - Display Options...

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

View Full Document
Ask a homework question - tutors are online