简体   繁体   English

在MATLAB中对分散的数据进行插值

[英]Interpolate on scattered data in MATLAB

I have some series of data (y axis) vs time (x axis) relationship. 我有一系列数据(y轴)与时间(x轴)的关系。 I want to find specific time value of a specific "y value" by interpolating. 我想通过插值找到特定“ y值”的特定时间值。 I tried to use interp1 command. 我尝试使用interp1命令。 But the problem is, the curve passes that "y value" at several time values. 但是问题是,曲线在多个时间值处传递了该“ y值”。 interp1 command only gives the first time value. interp1命令仅给出第一个时间值。 is there any way of performing interpolation so that i can find every time value? 有什么方法可以执行插值,以便我可以找到每个时间值?

thanks! 谢谢!

this is not a smart answer. 这不是一个明智的答案。 essentially you are trying to solve y(t)=c this can be written as f(t)=y(t)-c = 0 本质上您正在尝试求解y(t)=c这可以写成f(t)=y(t)-c = 0

then it remains to find the zero-crossings of function f(t) i guess there are functions to detect zero crossings or find roots of a dataset in matlab like fzero fnzero or crossing . 然后它仍然找到函数的零交叉f(t)我想有功能来检测过零点或找到一个数据集的根在像Matlab fzero fnzerocrossing but here is a home-made one to find points where value of a sine function is 0.5 但是这是一个自制的函数,可以找到正弦函数值为0.5的点

t=1:50;
y=sind(4*pi.*t);
plot(t,y);
hold on;

t1=1:0.02:50;
y1=interp1(t,y,t1,'spline');
plot(t1,y1,'k');

c=0.5;

f=y1-c;
nn=length(y1);

k=0;
for i=1:nn-1
    if f(i)*f(i+1) < 0
        k=k+1;
        allzeros(k)=i;
    end
end
plot(t1(allzeros),y1(allzeros),'+');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM