⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch2_6_2.htm

📁 一个不错的matlab工程实际问题的解决方法
💻 HTM
字号:
<! 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>)。要直接输出文字或是一数值,可使用<FONT COLOR=#FF0000>disp</FONT>,例如

<P>

<FONT COLOR=#FF0000>&gt;&gt; temp=20;</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; 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>则是用来控制输出数据及文字的格式,它的基本格式如

<P>

<FONT COLOR=#FF0000>&gt;&gt; fprintf('The area is %8.5f\n', area)

<BR>

</FONT>

<P>

在二个单引号间包括输出的字串<FONT COLOR=#FF0000>The area is</FONT>,接著是输出数据的格式<FONT COLOR=#FF0000>%8.5f</FONT>,再来是跳行符号以避免下一个输出

数据或是提示符号也挤在同一行,最后键入要输出的数据名<FONT COLOR=#FF0000>area</FONT>。例如

<P>

<FONT COLOR=#FF0000>&gt;&gt; fprintf('The area is %8.5f\n', area)

% 注意输出格式前须有%符号,跳行符号须有\符号</FONT>

<P>

<FONT COLOR=#FF0000>The area is 12.56637    % 输出值为8位数含5位小数

<BR>

</FONT>

<P>

在此要稍加说明的是输出数据的格式,以下的例子各说明了不同型态的输出格式

<P>

<FONT COLOR=#FF0000>&gt;&gt; fprintf('f_form: %12.5f\n',12345.2)

 % 输出值为12位数,含5位小数</FONT>

<P>

<FONT COLOR=#FF0000>f_form:  12345.20000</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; fprintf('f_form: %12.3f\n',1.23452)

 % 输出值为12位数,含3位小数</FONT>

<P>

<FONT COLOR=#FF0000>f_form:        1.235</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; fprintf('e_form: %12.5e\n',12345.2)

 % 输出值为指数格式的12位数,含5位小数</FONT>

<P>

<FONT COLOR=#FF0000>e_form: 1.23452e+004</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; fprintf('f_form: %12.0f\n',12345.2)

 % 输出值为整数格式的12位数</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> 上一页 下一页 讲义大纲 </FONT>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -