Interpolation of values in a table?

4 次查看(过去 30 天)
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 中查找有关 Spline Postprocessing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by