matlab reshape函數

來源:互聯網
上載者:User

標籤:matlab

文法

(1)B = reshape(A,m,n)

用法:
B=reshape(A,m,n) 返回m*n矩陣B,它的元素是獲得A的行寬度。如果A沒有m*n元素,得到一個錯誤結果。

例子:

<span style="font-size:18px;">>> A=rand(1,10)</span>
結果:

<span style="font-size:18px;">A =  Columns 1 through 8    0.1622    0.7943    0.3112    0.5285    0.1656    0.6020    0.2630    0.6541  Columns 9 through 10    0.6892    0.7482</span>

<span style="font-size:18px;">>> B=reshape(A,5,2)</span>
結果:
B =    0.1622    0.6020    0.7943    0.2630    0.3112    0.6541    0.5285    0.6892    0.1656    0.7482

(2)

B = reshape(A,m,n,p,...)

B = reshape(A,[m n p ...])
返回一個和A有相同元素的n維數組,但結構變為m * n * p * …

例如:

<span style="font-size:18px;">>> A=rand(1,12)</span>
結果:A矩陣
A =  Columns 1 through 8    0.4505    0.0838    0.2290    0.9133    0.1524    0.8258    0.5383    0.9961  Columns 9 through 12    0.0782    0.4427    0.1067    0.9619

>> D=reshape(A,2,3,2)D(:,:,1) =    0.4505    0.2290    0.1524    0.0838    0.9133    0.8258D(:,:,2) =    0.5383    0.0782    0.1067    0.9961    0.4427    0.9619

(3)

B = reshape(A,...,[],...)

>> C=reshape(A,5,[])
結果:

C =    0.1622    0.6020    0.7943    0.2630    0.3112    0.6541    0.5285    0.6892    0.1656    0.7482

(4)

B = reshape(A,siz)

返回一個與A相同元素的n維陣列,但是改造依據siz,一個向量改造改造的陣列的維度。數值prod(siz)必須和prod(size(A))相同。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.