站內搜尋

2006/1/4

Matlab - about Matrix

在網路上發現一位 matlab 超級達人,
也感謝他翻釋的文件,讓我在做 Project 時有相當充足的資料。

今天在寫 Matlab 程式,
發現在做 Matrix 的操作時,我需要將他由 vector,
重新定義進 Matrix 內,一般程式的直觀做法是寫一個 loop,
將他每一列掃進去便可以,但一直影影約約的感覺,
以 Matlab 這麼注重變化性的語言,不可能沒有提供這麼重要的語法,
結果總算讓我找到了。

在這裡提出官方的說明,以及引用 Jing 先生的翻譯。
RESHAPE Change size.
RESHAPE(X,M,N) returns the M-by-N matrix whose elements
are taken columnwise from X.  An error results if X does
not have M*N elements.

RESHAPE(X,M,N,P,...) returns an N-D array with the same
elements as X but reshaped to have the size M-by-N-by-P-by-...
M*N*P*... must be the same as PROD(SIZE(X)).

RESHAPE(X,[M N P ...]) is the same thing.

RESHAPE(X,...,[],...) calculates the length of the dimension
represented by [], such that the product of the dimensions
equals PROD(SIZE(X)). PROD(SIZE(X)) must be evenly divisible
by the product of the known dimensions. You can use only one
occurrence of [].

In general, RESHAPE(X,SIZ) returns an N-D array with the same
elements as X but reshaped to the size SIZ.  PROD(SIZ) must be
the same as PROD(SIZE(X)).
--------------------------------------------------------------

D = reshape(D,r,c); % 將向量變型為想要的r列c行
===========================================================
感謝網路上各位無私的貢獻。

By Lak

沒有留言:

張貼留言

熱門文章