2013-08-25 27 views
1

我在尺寸爲3x3x10的matlab中有了這個3-D數據。我想要的是將其重塑爲大小/尺寸爲10x9的數據。這樣對於每個i,j,1:10。我在這個新數據中有一列。我該怎麼做。我嘗試使用重塑(數據,10,9)。它給了我一個大小爲10x9的數據結構。但是,我懷疑它是如何安排它的。在matlab中對3D數據進行整形

我想重塑它只是如果new_data是我的新數據大小10x9,我的第一列是old_data(1,1,:)。我的新數據的第二列是OLD_DATA(1,2,:)等

回答

0

你可以這樣做:

for i = 1:size(x,3) 
    x(:,:,i) = x(:,:,i).'; 
end 
newData = reshape(x,[],size(x,3)).' 
+0

這不是我想要我的數據。請參閱我更新的問題 – user34790

1

我個人憎惡使用在Matlab for循環。我認爲一種更好的方法是對這些尺寸進行排列,然後重新塑造。此外,您要排列數據的順序並不明確。你應該能夠通過擺弄permute函數調用中的維數來實現你想要的。

% B is a 3x3x10, permute to 10x3x3, then reshape into 10x9 
% Change the ordering of the dimension in permute to achieve the desired result 
% remember: reshape takes elements out of B column by column. 

newB = reshape(permute(B,[3 1 2]),10,9); 

% newB is a 10x9 matrix, where each row is the entries of the 3x3 matrix 
% the first column is element 1:9:82 
+0

@dsgmt。我已經找到了解決方案(1小時前)。感謝您的幫助 – user34790

+0

這是什麼?有很多方法可以實現這一點,但有些方法比其他方法計算更好。 – dsgrnt

+0

我認爲你的解決方案是接近的,但你的置換參數應該是'[3 2 1]',因爲他想先拉出所有數據'old_data(1,1,:)',然後'old_data(1,2, :)'等等 – gnovice