필터 지우기
필터 지우기

Interpolation of values in a table?

조회 수: 3 (최근 30일)
Nick Haufler
Nick Haufler 2016년 2월 11일
댓글: Star Strider 2016년 2월 11일
Im trying to follow along with the directions in the attachment, and I got a table made which is T. AA_tire_degree1 is the values shown in table 2 of the pdf. I cant figure out how to get the nearest value, and the spline estimates for the table in the pdf. I've got code to calculate the nearest, but im not sure it is correct. Any help would be greatly appreciated.
clear all
tire=xlsread('tire_lab')
a=floor(linspace(22,222,10))
for k=1:10
AA_tire_degree(k)=tire(a(k),1);
deflection_mm(k)=tire(a(k),2);
end
AA_tire_degree=[-9.9000;-7.7000;-5.5000;-3.3000;-1.1000;1.2000;3.4000;5.6000;7.8000;10.1000]
deflection_mm=[138.0000;129.0000;109.0000;65.0000;24.0000;13.0000;24.0000;85.0000;173.0000;261.0100]
T=table(AA_tire_degree,deflection_mm)
% PercentError = abs(deflection_mm-deflection_mm(k))/deflection_mm*100
AA_tire_degree=[-9.9000;-7.7000;-5.5000;-3.3000;-1.1000;1.2000;3.4000;5.6000;7.8000;10.1000]
AA_tire_degree1=[-9.7; -6.7; 0.2; 4.3; 9.5]
Nearest=(interp1(AA_tire_degree,AA_tire_degree1,'nearest'))
  댓글 수: 3
M. A. Hopcroft
M. A. Hopcroft 2016년 2월 11일
I don't see an attachment. Maybe you can just state your question? What do you mean by "calculate the nearest"?
Nick Haufler
Nick Haufler 2016년 2월 11일
My bad, should have it now. sorry.

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

답변 (1개)

Star Strider
Star Strider 2016년 2월 11일
If you are allowed to use the interp1 function, see the documentation for it. It will do everything you need to do.
This assignment seems to be missing an argument:
Nearest=(interp1(AA_tire_degree,AA_tire_degree1,'nearest'));
what value of the independent variable do you want to interpolate to get the value you want?
  댓글 수: 2
Nick Haufler
Nick Haufler 2016년 2월 11일
AA_tire_degree=[-9.9000;-7.7000;-5.5000;-3.3000;-1.1000;1.2000;3.4000;5.6000;7.8000;10.1000]
deflection_mm=[138.0000;129.0000;109.0000;65.0000;24.0000;13.0000;24.0000;85.0000;173.0000;261.0100]
T=table(AA_tire_degree,deflection_mm)
% PercentError = abs(deflection_mm-deflection_mm(k))/deflection_mm*100
AA_tire_degree_int=[-9.7;6.7;0.2;4.3;9.5]
d_int_nearest = interp1(AA_tire_degree,deflection_mm,AA_tire_degree_int,'nearest')
d_int_linear = interp1(AA_tire_degree,deflection_mm,AA_tire_degree_int,'linear')
d_int_spline = interp1(AA_tire_degree,deflection_mm,AA_tire_degree_int,'spline')
Does this look right? The AA_tire_degree_int are the values from table 2 that are on the pdf that we want corresponding values of the deflection for. The outcomes for the nearest, linear, and spline all come out looking good at least. Before I got a bunch of NaN's in the column.
Star Strider
Star Strider 2016년 2월 11일
It looks correct to me.
If you got NaN values, it means you’re wanting to extrapolate. You have to tell interp1 that. The interp1 calls would then include the 'extrap' flag.
For example:
d_int_nearest = interp1(AA_tire_degree,deflection_mm,AA_tire_degree_int,'nearest','extrap')
and so for the others. That should eliminate the NaN elements.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by