-1

我正在使用 reshape 来显示我在 Matlab 中的一些数据。

   x = reshape(x, fs*W, []);

但是我拥有的数据是不均匀的:

   Eg.   1 2 3 4 5 6 7 
         8 9 1 2 3 4 5
         6 7 8

我收到一个错误,说 rehape 不适用于不均匀的尺寸:

          not divisible into total number of elements, xxxx

有没有解决的办法?

谢谢你的帮助

4

2 回答 2

3

您可以用零等填充剩余元素,NaN然后使用 reshape:

x = rand(13,1);
num_el = numel(x);
n = 3     % Number of rows
x(numel(x) + (n - mod(numel(x), n))) = 0;

x = reshape(x, n, [])
x =

   0.15991   0.99828   0.98674   0.06898   0.78390
   0.87197   0.63062   0.16429   0.06593   0.00000
   0.73633   0.41108   0.70827   0.55363   0.00000

此行:x(numel(x) + (n - mod(numel(x), n))) = 0;将值分配给0可被 整除的第一个值n。如果你愿意NaN,你可以这样做:

x(numel(x)+1:numel(x)+(n-mod(numel(x),3))) = NaN
于 2013-10-19T12:57:10.963 回答
0

你不能使用重塑来创建这样的东西,这不是矩阵。

要打印出您可能使用的数据:

fprintf('%3d%3d%3d%3d%3d%3d%3d\n',x);fprintf('\n')
于 2013-10-19T12:12:49.330 回答