Problem with interp1 function

조회 수: 1 (최근 30일)
Sowmya MR
Sowmya MR 2016년 9월 29일
답변: Walter Roberson 2016년 9월 29일
I have some issues with interp1 function. I have a time vector
t1=1/fs:1/fs:1/fs*1462805 where fs=250;
Now i have the output of a classifier where each value corresponds to a 8s epoch
annot=[zeros(1,600) ones(1,570)];
Now when i do
annotnew=interp1(annot,t1),
I get NaN's. Can someone help me fix this?
  댓글 수: 2
per isakson
per isakson 2016년 9월 29일
What result do you expect?
Sowmya MR
Sowmya MR 2016년 9월 29일
An output annotnew which is of length similar to t1 with real values (0's and 1's).

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 9월 29일
The syntax
annotnew=interp1(annot,t1)
is the same as
annotnew=interp1( 1 : length(annot), annot, t1)
and that implicitly indicates that the x values start from 1 and go upwards. You then ask to query at the positions in t1, some of which are probably less than 1, and some might be greater than length(annot) . Any position corresponding to a t1 whose value is less than 1 or greater than length(annot) is a request for extrapolation to before or after the data you provided, and the default behavior for extrapolation is to assign NaN there. See the 'extrap' keyword in interp1() if you want to change the extrapolation behavior.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by