?? ch2_6_2.htm
字號(hào):
<! Made by Html Translation Ver 1.0>
<HTML>
<HEAD>
<TITLE> 輸出格式 </TITLE>
</HEAD>
<BODY BACKGROUND="bg0000.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/bg0000.gif">
<FONT COLOR="#0000FF">
<H1>2.6.2 輸出格式</H1>
</FONT>
<HR>
<P>
至于輸出有二種格式:自由格式 (<FONT COLOR=#FF0000>disp</FONT>)
和格式化輸出 (<FONT COLOR=#FF0000>fprintf</FONT>)。要直接輸出文字或是一數(shù)值,可使用<FONT COLOR=#FF0000>disp</FONT>,例如
<P>
<FONT COLOR=#FF0000>>> temp=20;</FONT>
<P>
<FONT COLOR=#FF0000>>> disp(temp); disp('degrees C'); disp('度
C') %中文也接受呢!</FONT>
<P>
<FONT COLOR=#FF0000>20</FONT>
<P>
<FONT COLOR=#FF0000>degrees C</FONT>
<P>
<FONT COLOR=#FF0000>度 C<BR>
</FONT>
<P>
而指令<FONT COLOR=#FF0000>fprintf</FONT>則是用來控制輸出數(shù)據(jù)及文字的格式,它的基本格式如
<P>
<FONT COLOR=#FF0000>>> fprintf('The area is %8.5f\n', area)
<BR>
</FONT>
<P>
在二個(gè)單引號(hào)間包括輸出的字串<FONT COLOR=#FF0000>The area is</FONT>,接著是輸出數(shù)據(jù)的格式<FONT COLOR=#FF0000>%8.5f</FONT>,再來是跳行符號(hào)以避免下一個(gè)輸出
數(shù)據(jù)或是提示符號(hào)也擠在同一行,最后鍵入要輸出的數(shù)據(jù)名<FONT COLOR=#FF0000>area</FONT>。例如
<P>
<FONT COLOR=#FF0000>>> fprintf('The area is %8.5f\n', area)
% 注意輸出格式前須有%符號(hào),跳行符號(hào)須有\(zhòng)符號(hào)</FONT>
<P>
<FONT COLOR=#FF0000>The area is 12.56637 % 輸出值為8位數(shù)含5位小數(shù)
<BR>
</FONT>
<P>
在此要稍加說明的是輸出數(shù)據(jù)的格式,以下的例子各說明了不同型態(tài)的輸出格式
<P>
<FONT COLOR=#FF0000>>> fprintf('f_form: %12.5f\n',12345.2)
% 輸出值為12位數(shù),含5位小數(shù)</FONT>
<P>
<FONT COLOR=#FF0000>f_form: 12345.20000</FONT>
<P>
<FONT COLOR=#FF0000>>> fprintf('f_form: %12.3f\n',1.23452)
% 輸出值為12位數(shù),含3位小數(shù)</FONT>
<P>
<FONT COLOR=#FF0000>f_form: 1.235</FONT>
<P>
<FONT COLOR=#FF0000>>> fprintf('e_form: %12.5e\n',12345.2)
% 輸出值為指數(shù)格式的12位數(shù),含5位小數(shù)</FONT>
<P>
<FONT COLOR=#FF0000>e_form: 1.23452e+004</FONT>
<P>
<FONT COLOR=#FF0000>>> fprintf('f_form: %12.0f\n',12345.2)
% 輸出值為整數(shù)格式的12位數(shù)</FONT>
<P>
<FONT COLOR=#FF0000>f_form: 12345<BR>
</FONT><HR>
<A HREF="ch2_6_1.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch2_6_1.htm"><IMG SRC="lastpage.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/lastpage.gif" BORDER=0></A>
<A HREF="ch2_7.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch2_7.htm"><IMG SRC="nextpage-1.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/nextpage.gif" BORDER=0 HSPACE=10></A>
<A HREF="index.html" tppabs="http://166.111.167.223/computer/cai/matlabjc/index.html"><IMG SRC="outline-1.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/outline.gif" BORDER=0 HSPACE=6></A><BR>
<FONT SIZE=2 COLOR=#AA55FF> 上一頁(yè) 下一頁(yè) 講義大綱 </FONT>
</BODY>
</HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -