how to expand interp1 to an unknow value
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Eugene
le 30 Mai 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.
Plus de réponses (1)
the cyclist
le 30 Mai 2013
Modifié(e) : the cyclist
le 30 Mai 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) = [];
0 commentaires
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!