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

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

View Full Document Right Arrow Icon
More on fprintf, disp, and “if’s”
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
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’
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
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

ch3note2 - 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 Right Arrow Icon
Ask a homework question - tutors are online