2013-10-19 68 views
-1

我正在使用重塑来窗口我在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 

有没有解决的办法?

感谢所有帮助

+0

你还试过了什么? – nispio

回答

2

您可以在剩余的元素填充零,NaN等,然后用重塑:

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 
0

您不能创建使用重塑这样的事情,这是没有矩阵。

要打印出来的数据,你可以使用:

fprintf('%3d%3d%3d%3d%3d%3d%3d\n',x);fprintf('\n')