Interp1 returns NaN for all values

40 次查看(过去 30 天)
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);

采纳的回答

Abolfazl Chaman Motlagh
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)
ans = NaN
interp1([1 2],[2 4],0.5,'linear','extrap')
ans = 1
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 个评论
Abolfazl Chaman Motlagh
Hi, Happy to Help.
As you can see for example in Vehicle_speed_1 lowest value is 0.2890e+03 equal to 289. and highest is 1878.3. but in your code V which are the point you want to use interp1 on to find their value are between 1 and 75.
V = (1:0.25:75);
so this is why interp1 return NaN for all values. all of V points (query points) are outside of domain.
you can eather choose V points inside your domain ( for example here for Vehicle_speed_1 between 289 and 1873.3) or use 'extrap' as i mentioned before for extrapolation.
Amelia Hanson
Amelia Hanson 2021-12-8
Oh thank you so much, Vehicle_speed should be between 1 and 75 not 289 and 1873.3, I missed out a sign in one of the equations which is why its going wrong. Thank you!

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by