Chapter3-2c

# Chapter3-2c - means go to the next tab stop.) a=rand(3);...

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

More on fprintf, disp, and “if’s”

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

View Full Document
More on fprintf and disp The MATLAB  disp  function is used to display matrices  easily. If you want to display a matrix nicely with the  fprint  function, you will need to print each element  individually – a real nuisance. If you attempt to fprintf a matrix with a single fprintf  function, the results will be quite unpleasing: Try: a=rand(3); fprintf('The matrix is %g\n', a) Now try: disp(a)
More on fprintf and disp The fprintf problem can be fixed by using the %f formatting character and specifying the number of digits that will be displayed. The formatting string %6.4f means allow for 6 total digits with four of digits coming after the decimal point. This will make all numbers use the same number of digits. (The ‘\t’

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: means go to the next tab stop.) a=rand(3); fprintf(' The matrix is:\n\n'); fprintf('\t%6.4f\t%6.4f\t%6.4f\n\t%6.4f\t%6.4f\t%6.4f …\n\t%6.4f\t %6.4f\t%6.4f\n', a'); Seems hardly worth the effort and only good for a single sized matrix! Copy and paste in MATLAB Command Window and try it. Note the transpose A Variant of the “if” Statement – The ‘switch’ statement Is useful for testing multiple individual values (numeric or strings). It takes the form: SWITCH variable CASE case_expr statement, . .., statement CASE {case_expr1, case_expr2, case_expr3,. ..} statement, . .., statement ... OTHERWISE % optional statement, . .., statement END Acts like elseif, exits after 1 st branch executed Try Class Example 3_3...
View Full Document

## This note was uploaded on 09/13/2010 for the course EGR EGR115 taught by Professor Newman during the Spring '10 term at Embry-Riddle FL/AZ.

### Page1 / 4

Chapter3-2c - means go to the next tab stop.) a=rand(3);...

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

View Full Document
Ask a homework question - tutors are online