?? ch2_4_1.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.4.1 簡易陣列</H1>
</FONT>
<HR>
<P>
MATLAB的運算事實上是以陣列 (array) 及矩陣 (matrix) 方式在做運算,而這二者在MATLAB的基本運算性質不
同,陣列強調元素對元素的運算,而矩陣則采用線性代數的運算方式。在此只說明如何定義矩陣,至于矩陣的
詳細運算語法,我們將留待第四章再說明。
<BR>
<P>
而宣告一變數為陣列或是矩陣時,如果是要個別鍵入元素,須用中括號<FONT COLOR=#FF0000>[ ] </FONT>將元素置于其中。陣列為一維元素
所構成,而矩陣為多維元素所組成,例如
<P>
<FONT COLOR=#FF0000>>> x = [1 2 3] % 一維 1x3 陣列</FONT>
<P>
<FONT COLOR=#FF0000>>> x = [1 2 3; 4 5 6] % 二維 2x3 矩陣,以;區隔各列的元素</FONT>
<P>
<FONT COLOR=#FF0000>>> x = [1 2 3 % 二維 2x3 矩陣,各列的元素分二行鍵入</FONT>
<P>
<FONT COLOR=#FF0000>4 5 6]<BR>
</FONT>
<P>
假設要計算 <I>y = sin (x), 0 x π</I>而<I>x = 0, 0.2π, 0.4π,...,π</I>,即可用陣列方式運算,例如
<P>
<FONT COLOR=#FF0000>>> x = [0 0.2*pi 0.4*pi 0.6*pi 0.8*pi
pi] % 注意陣列內也可作運算</FONT>
<P>
<FONT COLOR=#FF0000>x =</FONT>
<P>
<FONT COLOR=#FF0000>0 0.6283 1.2566 1.8850 2.5133 3.1416</FONT>
<P>
<FONT COLOR=#FF0000>>> y=sin(x)</FONT>
<P>
<FONT COLOR=#FF0000>y =</FONT>
<P>
<FONT COLOR=#FF0000>0 0.5878 0.9511 0.9511 0.5878 0.0000<BR>
</FONT>
<P>
要找出陣列的某個元素或數個元素,可參考以下的例子
<P>
<FONT COLOR=#FF0000>>> x(3) % 第三個x的元素</FONT>
<P>
<FONT COLOR=#FF0000>ans =</FONT>
<P>
<FONT COLOR=#FF0000>1.2566</FONT>
<P>
<FONT COLOR=#FF0000>>> y(5) % 第五個y的元素</FONT>
<P>
<FONT COLOR=#FF0000>ans =</FONT>
<P>
<FONT COLOR=#FF0000>0.5878</FONT>
<P>
<FONT COLOR=#FF0000>>> x(1:5) % 列出第一到第五個x的元素</FONT>
<P>
<FONT COLOR=#FF0000>ans =</FONT>
<P>
<FONT COLOR=#FF0000>0 0.6283 1.2566 1.8850 2.5133</FONT>
<P>
<FONT COLOR=#FF0000>>> y(3:-1:1) % 列出第三到第一個y的元素,3為起始值,1為終止值,-1為增量</FONT>
<P>
<FONT COLOR=#FF0000>ans =</FONT>
<P>
<FONT COLOR=#FF0000>0.9511 0.5878 0</FONT>
<P>
<FONT COLOR=#FF0000>>> x(2:2:6) % 列出第二到第六個x的元素,2為起始值,6為終止值,2為增量</FONT>
<P>
<FONT COLOR=#FF0000>ans =</FONT>
<P>
<FONT COLOR=#FF0000>0.6283 1.8850 3.1416</FONT>
<P>
<FONT COLOR=#FF0000>>> y([4 2 5 1]) % 列出y元素,排列元素依序為原來y陣列的4,2,5,1個</FONT>
<P>
<FONT COLOR=#FF0000>ans =</FONT>
<P>
<FONT COLOR=#FF0000>0.9511 0.5878 0.5878 0</FONT><HR>
<A HREF="javascript:if(confirm('http://166.111.167.223/computer/tppmsgs/msgs0.htm \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://166.111.167.223/computer/tppmsgs/msgs0.htm#4'" tppabs="http://166.111.167.223/computer/tppmsgs/msgs0.htm#4"><IMG SRC="lastpage.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/lastpage.gif" BORDER=0></A>
<A HREF="ch2_4_2.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch2_4_2.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 + -