我有1x1点的矩阵,它指定了驱动器相对于时间的速度。这种速度在整个操作过程中发生这意味着两点之间的差异正在发生变化。
举个例子:M = [1; 2; 3; 5; 7; 9; 11; 15; 19]
。
(只有这是一个892x1矩阵)
我想让这个矩阵长两倍(因此改变每个时间步的相对速度),同时保持速度变化的方式。例如:M' = [1; 1.5; 2; 2.5; 3; 4; 5; 6; 7; 8; 9; 10; 11; 13; 15; 17; 19].
在MatLab中有一种简单的方法吗?
到目前为止,我已经尝试upsampling
(用零填充时间步长); interp
(用低通插值填充它。
谢谢!
答案 0 :(得分:4)
尝试
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
还接受其他参数,例如spline
或pchip
,允许您指定要使用的插值内核。请阅读help interp1
以获取更多信息。
或者,您可以使用类似
的内容pp = spline(t, M); % creates a cubic-splines interpolator
Mt = ppval(pp, t_new) % to evaluate M at all new times t_new