Interpolation of values in a table?

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 Comments

No attachment made it (pretty much par for the course, it's the klunky interface usually to blame)...after you select the file you then must use the "ATTACH" button at the LRH corner to actually do something.
I don't see an attachment. Maybe you can just state your question? What do you mean by "calculate the nearest"?
My bad, should have it now. sorry.

Sign in to comment.

Answers (1)

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 Comments

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.
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.

Sign in to comment.

Tags

Asked:

on 11 Feb 2016

Commented:

on 11 Feb 2016

Community Treasure Hunt

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

Start Hunting!