Effacer les filtres
Effacer les filtres

how to expand interp1 to an unknow value

1 vue (au cours des 30 derniers jours)
TheBeginner
TheBeginner le 30 Mai 2013
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

Réponse acceptée

Eugene
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.
  1 commentaire
TheBeginner
TheBeginner le 30 Mai 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!

Connectez-vous pour commenter.

Plus de réponses (1)

the cyclist
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) = [];

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by