2016-04-24 81 views
0

在下面的代碼中,我生成一個隨機的8×5矩陣,然後創建一個新的矩陣'temp',A被重構爲temp = reshape(A',r*c,1);。然後我對temp進行一些操作(但保持尺寸爲40 x 1)。你現在如何重組'temp'來取回維數爲A的矩陣(即現在恢復到8×5矩陣)?重構矩陣以得到原始矩陣

謝謝。下面是代碼,我到目前爲止有:

A = randi(10,8,5); 
[r c] = size(A); 
temp = reshape(A',r*c,1); 

回答

3

既然你從reshape操作構建temp矩陣AA')的轉置,你可以簡單地通過一個額外的重新變換回原來的A形式reshape操作適用於temp,但行和列計數分別爲rc,分別應用「反向」(分別爲列和行計數),然後最終轉置所得到的整形矩陣。

%// ... perform some manipulations (not affecting size) of temp 

%// restructure back to the form of A 
backToAForm = reshape(temp,c,r)'