cagri
cagri

Reputation: 71

Interpolate on scattered data in MATLAB

I have some series of data (y axis) vs time (x axis) relationship. I want to find specific time value of a specific "y value" by interpolating. I tried to use interp1 command. But the problem is, the curve passes that "y value" at several time values. interp1 command only gives the first time value. is there any way of performing interpolation so that i can find every time value?

thanks!

Upvotes: 0

Views: 267

Answers (1)

Guddu
Guddu

Reputation: 2437

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

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. but here is a home-made one to find points where value of a sine function is 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),'+');

Upvotes: 1

Related Questions