循环测量数据然后在Matlab中创建向量

时间:2014-10-04 15:25:39

标签: matlab matrix vector

我已经查看过以前的帖子,但还无法找到满意的解决方案。 我是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; ...],..到i600。这意味着基本上矢量i1将由列出的列1-7中的输入数据值构建,并且i2将包含列2-8,而i3列包含3-9,依此类推。正如您所看到的,因此我试图通过形成“重叠”来创建数据。 14x1输入向量。输出即o1,o2,..也将以完全相同的方式形成,只有矢量大小为21x1,我如何根据这些数据构建这些矢量? 我现在卡住了请帮忙,

提前谢谢:) Tee

1 个答案:

答案 0 :(得分:0)

% 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列。

相关问题