2013-11-26 81 views
0

我正在處理圖像數據,並且我有240個圖像,每個圖像由尺寸爲231的5個通道貢獻組成,共有384個。現在這個矩陣的大小是(240,231,384,5),我希望將其作爲(231 * 240,384,5)。我不能在不扭曲數據的情況下「重塑」它。我該怎麼做呢?在matlab中連接多維矩陣的一部分

+3

爲什麼不只是'重塑(數據,240 * 231,384,5)'? –

+0

我不明白你爲什麼想這樣做?第一維的手段是什麼意思? – Vuwox

+1

@Maria:你期望成爲M(2,:,:)的輸出結果?第一張照片的第二行或第二張照片的第一行? – Daniel

回答

0

這是我的猜測是你正在嘗試做的

test = [1:16]; % sample data 
test1 = reshape(test, 4, 4); % rearrange to 4x4 
% this has a vertical arrangement which is prob not what you have 

[m, n] = size(test1); % get dims 
r = 2; % horizontal width/numb of cols 
% this prob closer to what you have 
test2 = test1(:,1:r)' % flip to horizontal order 
test3 = reshape(test2, m*r, 1) % rearrange to vertical 
+0

正如Daniel R所說,請包括您正在尋找的示例輸出。目前尚不清楚你想要做什麼。什麼失真在說什麼?你的數據是什麼樣的?你能給我們一小部分的代碼與你期望的輸出嗎? – athypes

0

給定一個矩陣:

n1 = 240; n2 = 231; n3 = 384; n4 = 5; 
A = randn(n1, n2, n3, n4); 

我猜你正在尋找的解決方法是,由路易斯以上建議:

B = reshape(A, n1 * n2, n3, n4); 

C = reshape(permute(A, [2 1 3 4]), n1 * n2, n3, n4); 

否則,你必須更好地解釋你的問題是什麼。