【正文】
ments and Program Design 10/23/2022 Hangzhou Dianzi University 75 Enhanced Control of Text String The font used to display the text can be modified by stream modifier. Stream modifier : a special sequence of characters that tells the MATLAB interpreter to change its behavior. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 76 \bf Boldface \it Italics \rm Restore normal font \fontname{fontname} Specify the font name to use \fontsize{fontsize} Specify font size _{xxx} The characters inside the braces are subscripts. ^{xxx} The characters inside the braces are superscripts Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 77 Special Greek and mathematical symbols are created by embedding special escape sequences into the text string. Escape sequences : are subset of the special sequences support by the TEX language. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 78 Character Sequence Symbol Character Sequence Symbol Character Sequence Symbol \alpha α \int ∫ \beta β \cong ≌ \gamma γ \Gamma Γ \sim ~ \delta δ \Delta Δ \infty ∞ \epsilon ε \pm 177。 , 39。 , 6 , …39。 , 39。Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 71 Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 72 Enhanced Control of Plotted Lines LineWidth Specifies the width of each line in pionts. MarkerEdgeColor Specifies the color of the marker or the edge color for filled markers. MarkerFaceColor Specifies the color of the face of filled markers. MarkerSize Specifies the size of marker in points. plot (x, y, ?PropertyName‘, value, …) Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 73 Example x = 0 : pi / 15 : 4 * pi 。plot ( x , y ) 。 ) 。y = s in ( x ) 。plot ( x , y 2 ) 。y 1 = exp ( x ) 。 cos x 39。hold off 。hold on 。y 2 = cos ( x ) 。 P l o t o f s i n ( x ) v s x 39。 garbage 1 2 3 garbage (?1‘, ?2‘, ?3‘) Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 59 Only functions with character arguments can be treated as mands. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 60 x = 2 * pi : pi / 20 : 2 * pi 。endChapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 54 Quiz Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 55 Additional Plotting Features Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 56 Controlling x and yaxis Plotting Limits To display only the subset of the data that you are interest. axis mand/function Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 57 Command Description v = axis。 num 2 str ( a ( i nd ex ) ) ] ) 。 di s p ([ 39。 end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 52 The try/catch Construct Special form branching construct designed to trap error. tr yS ta te m e nt 1 S ta te m e nt 2 T r y B l oc kc a tc hS ta te m e nt 1 S ta te m e nt 2 Ca tc h B l oc ke nd??????????Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 53 % I ni t i al i ze a r r aya = [ 1 3 2 5 ] 。)。The value is odd.39。 else disp (39。)。The grade is B.39。 end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 45 (b) if grade disp (39。)。The grade is C.39。 elseif grade disp (39。)。This equation has two identical real roots.39。 ?try/catch Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 28 The if Construct if c o n tr o l _ e x p r _ 1S ta te m e n t 1S ta te m e n t 2 B l o c k 1e l se if c o n tr o l _ e x p r _ 2S ta te m e n t 1S ta te m e n t 2 B l o c k 2e l seS ta te m e n t 1S ta te m e n t 2 B l o c k 3e n d???????????????Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 29 There can be any number of elseif clause in an if construct, but there can be at most one else clause. Note that the MATLAB keyword end in this construct is different from the function end. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 30 Quadratic equation ?If , 2 distinct real roots. ?If , single root. ?If , 2 plex roots 2 0a x b x c? ? ?2 42b b a cxa? ? ??2 40b ac??2 40b ac??2 40b ac??Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 31 if (b^2 4*a*c) 0 Write msg that equation has two plex roots. elseif (b^2 4*a*c) == 0 Write msg that equation has two identical real roots. else Write msg that equation has two distinct real roots. end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 32 if (b^2 4*a*c) 0 disp (39。 value2 | value3 (e) value1 amp。 l2 l1 | l2 xor (l1, l2) ~ l1 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 Chapter 3 Branching Statements and Program Design 10