필터 지우기
필터 지우기

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 CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by