Hey all,
I have a function that I am using as part of another program, and it relies on interp1, however, my interp1 function is not returning a mix of NaNs and numbers. Here is my code:
function [T] = thrust(t);
thrust_time = xlsread('rocketdata.xlsx')
e = length(thrust_time)
time_reduced = thrust_time((1:e),2);
thrust_reduced = thrust_time((1:e),1);
A = interp1(time_reduced,thrust_reduced)
T = A(t)
end
where the XLS file has 2 columns of 153 rows. The first column is Thrust, and the second column is time. All values are positive, but the first ~25 and last ~25 thrust values are decimals less than 1 but greater than zero, which return NaN. All thrust values greater than 1 return actual numbers.
Can anyone please tell me what I am doing wrong? Thank you!

 채택된 답변

Star Strider
Star Strider 2014년 4월 29일
편집: Star Strider 2014년 4월 29일

1 개 추천

I don’t know what the contents and ranges of time_reduced and thrust_reduced are. I suspect you may be asking interp1 to interpolate values not within the range of the data, but that’s only a guess. You will need to specify a third argument to interp1 if you want it to interpolate values for thrust_reduced at new times for time_reduced.
From the documentation on interp1:
vq = interp1(v,xq) returns interpolated values and assumes a default set of sample point coordinates. The default points are the sequence of numbers from 1 to n, where n depends on the shape of v:
  • When v is a vector, the default points are 1:length(v) .
  • When v is an array, the default points are 1:size(v,1) .
Use this syntax when you are not concerned about the absolute distances between points.

댓글 수: 2

Joey
Joey 2014년 4월 30일
Thank you, i finally got it to work!
Star Strider
Star Strider 2014년 4월 30일
My pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2014년 4월 29일

댓글:

2014년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by