我已经看过以前的帖子了,但还没有找到一个令人满意的解决方案。我对Matlab很陌生,有输入/输出设备数据,我已经把这些数据排列成列向量,现在我需要在整个数据文件中循环等大小的窗口,在每个实例中创建相同大小的向量。数据有600列作为下面的示例表。对不起,它看起来不太好,因为它不允许我正确地编辑它:所有向量i2,i3,i4,.,i600的构建方式与i1完全相同。
数据类型____ 列1…600
输入
0.20 0.37 0.21 -0.04 …
-0.06 0.01 0.31 0.17 ...
输出
0.34 -0.08 0.59 -0.04 …
0.11 0.06 0.72 0.18 …
-0.27 0.09 0.59 0.03 …
每个向量将从数据中得到14个元素。i1=0.20;-0.06;0.37;0.01;0.21;0.31;-0.04;0.17;…,i2=0.37;0.01;0.21;0.31;-0.04;0.17;…,i3=0.21;0.31;-0.04;0.17;.,..to i600。这意味着从本质上说,向量i1将由所列1-7列中的输入数据值构建,而i2将包含2-8列,而i3列3-9等等。正如您所看到的,因此,我试图通过形成‘重叠’14x1输入向量来创建数据。输出,即o1,o2,..will也是以完全相同的方式形成的,只是向量的大小为21x1,如何从这些数据构建这些向量?我被困住了,请帮帮忙,
预先谢谢:)
发布于 2014-10-06 19:17:42
% Make a 2x600 array with random entries.
Q = rand( 2, 600 );
% The offset for the beginning of each
% set we want to extract from the above
% array. We subtract 7 from 600 since we are
% pulling off 14 elements at a time and thus
% have to stop at the 7th-to-last column.
offsets = 2 * ( 0 : 600 - 7 );
% These are indices of the elements we want
% organized by column. All we have to do is
% offset the numbers 1 thorugh 14 by the
% amounts found above.
v = (1:14)';
inds = repmat( v, 1, length( offsets ) ) + repmat( offsets, length(v), 1 );
% Now we can pull off the overlapping submatrices we want.
C = Q(inds);
下面是一些输出示例:
>> Q(:,1:10)
ans =
0.8147 0.1270 0.6324 0.2785 0.9575 0.1576 0.9572 0.8003 0.4218 0.7922
0.9058 0.9134 0.0975 0.5469 0.9649 0.9706 0.4854 0.1419 0.9157 0.9595
>> C(:,1:2)
ans =
0.8147 0.1270
0.9058 0.9134
0.1270 0.6324
0.9134 0.0975
0.6324 0.2785
0.0975 0.5469
0.2785 0.9575
0.5469 0.9649
0.9575 0.1576
0.9649 0.9706
0.1576 0.9572
0.9706 0.4854
0.9572 0.8003
0.4854 0.1419
您可以看到,C
的第一行是Q
的前7列,第二列是Q
的2-8列。
https://stackoverflow.com/questions/26194227
复制相似问题