1

我在尺寸为 3x3x10 的 matlab 中有这个 3-D 数据。我想要的是将其重塑为大小/尺寸 10x9 的数据。这样对于每个 i,j,1:10。我在这个新数据中有一列。我该怎么做。我尝试使用重塑(数据,10,9)。它给了我一个大小为 10x9 的数据结构。但是,我怀疑它是如何安排的。

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

4

2 回答 2

1

我个人讨厌for在 Matlab 中使用循环。我认为更好的方法是排列尺寸,然后重塑。此外,还不清楚您要排列数据的顺序。您应该能够通过摆弄 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
于 2013-08-25T22:54:23.497 回答
0

你可以这样做:

for i = 1:size(x,3)
    x(:,:,i) = x(:,:,i).';
end
newData = reshape(x,[],size(x,3)).'
于 2013-08-25T21:49:55.203 回答