如何在MatLab中进行插值

如何在MatLab中进行插值

本文介绍了如何在MatLab中进行插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个1x1的点矩阵,该矩阵指定驱动器相对于时间的速度.在整个操作过程中,该速度会发生变化.这意味着两点之间的差异正在改变.

I have a 1x1 Matrix of points which specifies speed of a drive with respect to time. This speed changes throughout the operation; which means that the difference between two points is changing.

举个例子:M = [1; 2; 3; 5; 7; 9; 11; 15; 19].(只有一个892x1矩阵)

To give you an example: M = [1; 2; 3; 5; 7; 9; 11; 15; 19].(Only that this is a 892x1 matrix)

我希望将此矩阵的长度加倍(以便更改每个时间步的相对速度),同时保留速度更改的方式.例如:M' = [1; 1.5; 2; 2.5; 3; 4; 5; 6; 7; 8; 9; 10; 11; 13; 15; 17; 19].

I want to make this matrix twice as long (so changing the relative speed per timestep), while retaining the way the speeds change. Eg: M' = [1; 1.5; 2; 2.5; 3; 4; 5; 6; 7; 8; 9; 10; 11; 13; 15; 17; 19].

在MatLab中有一种简单的方法吗?

Is there an easy way to do this in MatLab?

到目前为止,我已经尝试过upsampling(它用零填充时间步长); interp(使用低通插值填充.

So far I have tried upsampling (which fills the time step with zeros); interp (which fills it with low-pass interpolation.

谢谢!

推荐答案

尝试

M = [1; 2; 3; 5; 7; 9; 11; 15; 19];

% create new time, with twice as many sampling times
t_new = linspace(1, numel(M), 2*numel(M)-1);

% interpolate
Mt = interp1(M, t_new),

请注意,interp1还接受其他参数,例如splinepchip,这些参数允许您指定要使用的插值内核.阅读help interp1了解更多信息.

Note that interp1 also accepts additional arguments, like spline or pchip that allow you to specfify what interpolation kernel to use. Read help interp1 for more information.

或者,您可以使用类似的

Alternatively, you can use something like

pp = spline(t, M);    % creates a cubic-splines interpolator
Mt = ppval(pp, t_new) % to evaluate M at all new times t_new

这篇关于如何在MatLab中进行插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:15