调整矢量的步长和窗口大小 [英] Reshape vector with a step and window size

查看:101
本文介绍了调整矢量的步长和窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个向量

A = [1 2 3 4 5 6 7 8]

我想使用windowsize=4stepsize=2将其重塑"为矩阵,以使结果矩阵为

I want to "reshape" it to matrix with windowsize=4 and stepsize=2, such that the resulting matrix is

b = [ 1   3   5;   
      2   4   6;   
      3   5   7;   
      4   6   8 ]

推荐答案

您可以设置索引矩阵,然后只需索引到A ...

You can set up an indexing matrix, then just index into A...

A = [1 2 3 4 5 6 7 8];

windowsize = 4;
stepsize = 2;

% Implicit expansion to create a matrix of indices
idx = bsxfun( @plus, (1:windowsize).',  0:stepsize:(numel(A)-windowsize) );

b = A(idx);

注意;在这种情况下,idxb是相同的,但是您需要在最后的索引步骤中假设A不仅仅是实际示例中的连续整数.

Note; in this case idx and b are the same, but you need the final indexing step assuming A isn't just consecutive integers in your real example.

这篇关于调整矢量的步长和窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆