-
reshape
鎖定
- 外文名
- reshape
- 類 別
- 計算機編程
- 功 能
- 矩陣變換
- 應 用
- MATLAB
- 語 法
- reshape(A,size)
reshapereshape語法
B = reshape(A,m,n)
B = reshape(A,m,n,p,...)
B = reshape(A,[m n p ...])
B = reshape(A,...,[ ],...)
B = reshape(A,size)
reshape調用格式説明
B = reshape(A,m,n)
返回一個m*n的矩陣B, B中元素是按列從A中得到的。如果A中元素個數沒有m*n個, 則會引發錯誤。
B = reshape(A,m,n,p,...)和B = reshape(A,[m n p ...])
B = reshape(A,...,[ ],...)
reshape應用示例
調整一個3*4矩陣到2*6矩陣(內容與圖冊相同):
A =
1 4 7 10
2 5 8 11
3 6 9 12
B = reshape(A,2,6)
B =
1 3 5 7 9 11
2 4 6 8 10 12
B = reshape(A,2,[])
B =
1 3 5 7 9 11
2 4 6 8 10 12
reshape延伸拓展
repmat函數與reshape函數功能比較:
(1)repmat函數
repmat函數主要是用於快速的產生一個矩陣,它的用法一般有下面幾種:
B = repmat(A,M,N)
矩陣B是矩陣A的複製品,其中B的維度為[size(A,1)*M, size(A,2)*N]。寫成repmat(A,[M,N])也是可以的;如果寫成repmat(A,N),那麼它等價於repmat(A,N,N)或者repmat(A,[N,N])。
[3]
(2)示例
repmat(magic(2),2)
ans =
1 3 1 3 4 2 4 2 1 3 1 3 4 2 4 2