フィルターのクリア

how to expand interp1 to an unknow value

1 回表示 (過去 30 日間)
TheBeginner
TheBeginner 2013 年 5 月 30 日
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

採用された回答

Eugene
Eugene 2013 年 5 月 30 日
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 件のコメント
TheBeginner
TheBeginner 2013 年 5 月 30 日
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!

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2013 年 5 月 30 日
編集済み: the cyclist 2013 年 5 月 30 日
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) = [];

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by