필터 지우기
필터 지우기

How to interpolate a value between two values in an array?

조회 수: 23 (최근 30일)
Arman Kam
Arman Kam 2012년 7월 26일
Hi,i have an array named sumNy. the content of sumNy gives me Ny and the number of it's cells show me corresponding accelerations. now i have a specified Ny that is between two Ny s in my sumNy array, and i want to obtain it's corresponding acceleration.
i wrote this code but i dont know why it is not working
for i=1:150
if i==1
y=0;
elseif sumNy1(1,i-1)<=(1/475) & sumNy1(1,i)>=(1/475)
y=(((1/475)-sumNy1(1,i))/(sumNy1(1,i-1)-sumNy1(1,i)))*(i-1)+(1-(((1/475)- sumNy1(1,i))/(sumNy1(1,i-1)-sumNy1(1,i))))*(i);
end
end
please help me
Thanks
  댓글 수: 2
Arman Kam
Arman Kam 2012년 7월 26일
i must say that (1/475) is my specified Ny
Arman Kam
Arman Kam 2012년 7월 26일
and by the way, there is two Ny s in my array that the specified Ny (1/475) place between them, so that is not why everytime i run this code it gives me y=0 !

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

답변 (2개)

Wayne King
Wayne King 2012년 7월 26일
Have you tried interp1?
For example:
t = 0:10; x = sin(t);
tnew = 0:.25:10;
xnew = interp1(t,x,tnew);
plot(t,x,'o',tnew,xnew)
  댓글 수: 2
Arman Kam
Arman Kam 2012년 7월 26일
i dont know what to put as a function in interp1 that gives me linear interpolation.
Arman Kam
Arman Kam 2012년 7월 26일
i think the code i wrote do what i want but everytime i try this code the value of y will be zero!
would you please help me whats wrong with this code?!

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


Arman Kam
Arman Kam 2012년 7월 26일
sorry friends, i just find out my horrible mistake!
but still if you have a better way to do this please tell me

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by