how to expand interp1 to an unknow value

4 visualizzazioni (ultimi 30 giorni)
Hi everybody,
I have a 5 values correspond to 5 points. The curve is decreasing quite linearly and when I interpolate these datas inside the points limit, it works quite well :
Vect_freq_1 = [0, 0.5, 0.9, 1.5, 2]; %cy/mrad
Vect_FTM_1 = [1, 0.83, 0.51, 0.26, 0.15];
Vect_freq = linspace(0,2,400);
Vect_FTM = interp1(Vect_freq_1,Vect_FTM_1,Vect_freq,'linear');
plot(Vect_freq,Vect_FTM);
Now I would like to interpolate outside the last data so that the curve reach 0 :
Vect_freq_1 = [0, 0.5, 0.9, 1.5, 2]; %cy/mrad
Vect_FTM_1 = [1, 0.83, 0.51, 0.26, 0.15];
Vect_freq = linspace(0,3,400); %2 is replaced by 3
Vect_FTM = interp1(Vect_freq_1,Vect_FTM_1,Vect_freq,'linear','extrap');
plot(Vect_freq,Vect_FTM);
However when I do this, instead of reaching 0, interp1 acts as if 3 were the equal to the last value (2)...
Any idea on how to do make the curve reach 0 without adding a fake value?
Thank you

Risposta accettata

Eugene
Eugene il 30 Mag 2013
When I tried your example I didn't have a problem. I get a straight line from x,y=2,0.15 to x,y=3,-0.07 with the gradient the same as the last two points.
  1 Commento
TheBeginner
TheBeginner il 30 Mag 2013
Oh my god, you're right...
Everytime I would plot it, the y-scale would change but I didn't see it so I thought the algorithm was not doing the right thing...
Sorry for the question, thank you!

Accedi per commentare.

Più risposte (1)

the cyclist
the cyclist il 30 Mag 2013
Modificato: the cyclist il 30 Mag 2013
It is not perfectly clear to me what you are trying to do. Are you saying that you want the line to stop when Vect_FTM is equal to zero, instead of going all the way to Vect_freq=3 (which you put in)?
If all you care about is the plot, then you could just remove the values in those vectors when Vect_FTM is less than zero. Put these lines in before you plot:
idx = (Vect_FTM<0);
Vect_FTM(idx) = [];
Vect_freq(idx) = [];

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by