Interp1 returns NaN for all values
89 views (last 30 days)
Show older comments
Amelia Hanson
on 8 Dec 2021
Commented: Amelia Hanson
on 8 Dec 2021
Hi, my code seems to be returning NaN for all values of Tractive_effort_V1, Tractive_effort_V2 etc.. Im not sure why its returning NaN instead of values. Any help would be greatly appreciated.
Here is my code so far:
Engine_Speed = [1000, 1250, 1500, 1600, 1750, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6200, 6500];
Engine_Torque = [156.0784, 200.4152, 289.3725, 306.2588, 322.3529, 357.6471, 357.6471, 357.6471, 357.6471, 357.6471, 357.6471, 353.1313, 358.2166, 352.1367, 326.1142, 261.8453];
Gear_Ratios = [3.4100, 2.0500, 1.4300, 1.1000, 0.9000, 0.7900];
V = (1:0.25:75);
Fd = 0.5*rho*Cd*A*V.^2+Vehicle_Mass*g*(ad+bd*V);
Vehicle_speed_1 = (Engine_Speed*Rolling_Radius)/((Gear_Ratios(1)*Final_Drive_Ratio)*2*pi/60);
Vehicle_speed_2 = (Engine_Speed*Rolling_Radius)/((Gear_Ratios(2)*Final_Drive_Ratio)*2*pi/60);
Vehicle_speed_3 = (Engine_Speed*Rolling_Radius)/((Gear_Ratios(3)*Final_Drive_Ratio)*2*pi/60);
Vehicle_speed_4 = (Engine_Speed*Rolling_Radius)/((Gear_Ratios(4)*Final_Drive_Ratio)*2*pi/60);
Vehicle_speed_5 = (Engine_Speed*Rolling_Radius)/((Gear_Ratios(5)*Final_Drive_Ratio)*2*pi/60);
Vehicle_speed_6 = (Engine_Speed*Rolling_Radius)/((Gear_Ratios(6)*Final_Drive_Ratio)*2*pi/60);
Tractive_effort_1 = (Engine_Torque*Final_Drive_Ratio*Gear_Ratios(1)*trans_eff/Rolling_Radius);
Tractive_effort_2 = (Engine_Torque*Final_Drive_Ratio*Gear_Ratios(2)*trans_eff/Rolling_Radius);
Tractive_effort_3 = (Engine_Torque*Final_Drive_Ratio*Gear_Ratios(3)*trans_eff/Rolling_Radius);
Tractive_effort_4 = (Engine_Torque*Final_Drive_Ratio*Gear_Ratios(4)*trans_eff/Rolling_Radius);
Tractive_effort_5 = (Engine_Torque*Final_Drive_Ratio*Gear_Ratios(5)*trans_eff/Rolling_Radius);
Tractive_effort_6 = (Engine_Torque*Final_Drive_Ratio*Gear_Ratios(6)*trans_eff/Rolling_Radius);
Tractive_effort_V1 = interp1(Vehicle_speed_1,Tractive_effort_1,V);
Tractive_effort_V2 = interp1(Vehicle_speed_2,Tractive_effort_2,V);
Tractive_effort_V3 = interp1(Vehicle_speed_3,Tractive_effort_3,V);
Tractive_effort_V4 = interp1(Vehicle_speed_4,Tractive_effort_4,V);
Tractive_effort_V5 = interp1(Vehicle_speed_5,Tractive_effort_5,V);
Tractive_effort_V6 = interp1(Vehicle_speed_6,Tractive_effort_6,V);
0 Comments
Accepted Answer
Abolfazl Chaman Motlagh
on 8 Dec 2021
According to documentation of interp1. the function returns NaN for points outside the domain. so check V and See if it's point are inside of domain Vehicle_speed. even if not by option 'extrap' you can make function to return specific number by extrapolation. for example :
interp1([1 2],[2 4],0.5)
interp1([1 2],[2 4],0.5,'linear','extrap')
you can see it returns a number.
so add option 'extrap'. like :
Tractive_effort_V1 = interp1(Vehicle_speed_1,Tractive_effort_1,V,'linear','extrap');
but i recommend check your variables first, because it seems you want interpolation, not extrapolation.
3 Comments
More Answers (0)
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!