User Tools

Site Tools


gibson:teaching:spring-2016:math445:lecture:forloop

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gibson:teaching:spring-2016:math445:lecture:forloop [2016/02/17 06:58]
gibson
gibson:teaching:spring-2016:math445:lecture:forloop [2016/02/17 07:38] (current)
gibson
Line 29: Line 29:
  
 The decimal and floating-point slots can be specialized to print numbers in particular ways, for example, The decimal and floating-point slots can be specialized to print numbers in particular ways, for example,
-''​fprintf('​The value of pi is %8.3f',​ pi)''​ will print '' ​  3.142'',​ that is, pi with 3 digits after the decimal in a fixed-width field of 8 characters.+ 
 +<code matlab>​ 
 +>> ​fprintf('​The value of pi is %8.3f\n', pi) 
 +The value of pi is    ​3.142 
 +</​code>​  
 + 
 +This prints $\piwith 3 digits after the decimal in a fixed-width field of 8 characters.
  
 You can put as many slots in a format string as you like. Just provide as many variables as slots, and make sure the types of the slots match the variables. You can put as many slots in a format string as you like. Just provide as many variables as slots, and make sure the types of the slots match the variables.
gibson/teaching/spring-2016/math445/lecture/forloop.1455721117.txt.gz · Last modified: 2016/02/17 06:58 by gibson