Matlab重采样向量 [英] Matlab resampling vectors

查看:219
本文介绍了Matlab重采样向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试寻找一种对向量进行重采样的方法.因此,例如,如果我有一个大小为4 [1 3 5 7]的向量,并且我想将其缩小为大小3,它会给我[1 4 8]或类似的东西.放大时也一样,但方向相反.

I'm currently trying to find a way to resample vectors. So for example if I have a vector of size 4 [1 3 5 7] and I want to shrink it to size 3 it would give me [1 4 8] or something like that. Same for enlarging but in the opposite way.

我已经搜索并找到了函数 Interp Decimate ,它们实际上是这样做的,但是问题是我没有整数放大或缩小因子.我的矢量大小为140到160,我希望它们的大小都为150. Interp Decimate 无法做到这一点,因为它们仅适用于整数因子

I have searched and found the function Interp and Decimate, which actually do this, but the problem is that I don't have an integer enlarging or shrinking factor. I have vectors of size 140 to 160 and I want them all to be of size 150. This can't be done with Interp or Decimate because they only work with integer factors.

所以我想知道,是否有任何快速方法可以做到这一点,或者我实际上必须想出一种巧妙的方法来进行这种重塑?

So I'm wondering, is there any fast way to do this or do I actually have to think of a clever way to do this reshaping?

预先感谢

推荐答案

如果我正确理解了您的问题,则希望重新采样.您可以做的是在MATLAB中使用 interp1 ,但是您可以指定从要采样的起点到终点的点范围,此范围内的点数是所需输出的点总数.

If I understand your problem correctly, you would like to resample a data vector. What you can do is use interp1 in MATLAB, but you specify a range of points from the beginning of where you want to sample to the end, and the number of points within this range is the total number of points for your desired output.

要完成所需的操作,请使用 linspace .此外,您可以使用要重新采样的数组作为输出y值,并使用为每个值定义的 dummy x值在您要重新采样的数组中.像x = [1 2 ... ]这样简单的事情,只要向量中的元素数量最多,都可以.

To accomplish what you want, use linspace. In addition, you would use the array you want to resample as the output or y values, and you would use dummy x values that are defined for each value in the array you are trying to resample. Something simple like x = [1 2 ... ] up to as many elements as there are in your vector would work.

使用您的小示例,请执行以下操作:

Working with your small example, do this:

a = [1 3 5 7];
x = 1 : numel(a);
xp = linspace(x(1), x(end), 3); %// Specify 3 output points
y = interp1(x, a, xp)

y =

     1     4     7

因此,对于您的特定情况,请更改代码的第三行,以便将3更改为150.定义a由您决定,但是第二行代码和最后一行代码应保持不变.

Therefore, for your specific case, change the third line of your code so that 3 is changed to 150. Defining a is up to you, but the second line of code and last line of code should stay the same.

上述方法的优点是不假定数据向量在增加或减少.实际上,它可以是随机的.应该发生的是,给定所需的点数,您的数据(存储在a中)将被重新采样.

The advantage of the above approach is that the data vector is not assumed to be increasing or decreasing. In fact, it can be all random. What should happen is that your data (stored in a) will be resampled given your desired number of points.

这篇关于Matlab重采样向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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