how to interpolate for increasing - decreasing type of data set

5 次查看(过去 30 天)
i am trying to get result for following code however I get NaN as result. Please help me correct my code
rpm1=[1000,2000,2500,3000,3500,4000,4500,4750,5320,5800,6000]; %engine rpm from table
theta1=[100;80;60;40;20;1]; %throttle from table
tr1=[117.200000000000,123.600000000000,129.100000000000,132.100000000000,134.300000000000,137.200000000000,134.800000000000,135.200000000000,129,119.300000000000,113.100000000000;115.300000000000,121.900000000000,127.300000000000,131.100000000000,120.500000000000,125.500000000000,124.500000000000,125.100000000000,118.800000000000,109.600000000000,104.700000000000;106,103.600000000000,96.7000000000000,89.6000000000000,86.4000000000000,80.9000000000000,74,69.8000000000000,55.7000000000000,45.8000000000000,41.2000000000000;98,85.9000000000000,77.6000000000000,69.3000000000000,63.8000000000000,56.9000000000000,50.5000000000000,46,32.2000000000000,21.3000000000000,17.4000000000000;65.4000000000000,45.7000000000000,37.2000000000000,27.8000000000000,23.5000000000000,19.1000000000000,15.6000000000000,11.9000000000000,0,0,0;0,0,0,0,0,0,0,0,0,0,0]; %torque from table
rpm1out=[1000;1400;1700;1900;3300;3500;3700;4100;4700;4900;5200;5400]; %sample rpm
tr1out=[95.4929658551372;102.313891987647;101.110199140734;100.518911426460;115.749049521378;122.776670385176;129.044548452888;128.100320049574;121.905913857622;126.674342460896;128.548223266531;127.323954473516]; %sample torque
theta1out=interp2(rpm1,theta1,tr1,rpm1out,tr1out); %desired throttle values for sample rpm and sample torque values
  3 个评论
Aditya Gandhi
Aditya Gandhi 2021-7-1
Thank You. Sir I did not understand the approach you suggested earlier. Please can you refer me to a similar exaple if possible. I am short on time and hence trying everything i can find
Stephen23
Stephen23 2021-7-1
编辑:Stephen23 2021-7-1
"I did not understand the approach you suggested earlier."
I did not suggest a complete approach; I recommended where you could start looking.
"Please can you refer me to a similar exaple if possible."

请先登录,再进行评论。

回答(3 个)

Chunru
Chunru 2021-7-1
Since tr1out is outside the range of theta1, you are doing extropolation as well. For the default interpolation method, the extrapolated values are NaN. To generate some extrapolated data, specify a different interpolation method such as spline. Be careful to use the extropolated data!!
rpm1=[1000,2000,2500,3000,3500,4000,4500,4750,5320,5800,6000]; %engine rpm from table
theta1=[100;80;60;40;20;1]; %throttle from table
tr1=[117.200000000000,123.600000000000,129.100000000000,132.100000000000,134.300000000000,137.200000000000,134.800000000000,135.200000000000,129,119.300000000000,113.100000000000;115.300000000000,121.900000000000,127.300000000000,131.100000000000,120.500000000000,125.500000000000,124.500000000000,125.100000000000,118.800000000000,109.600000000000,104.700000000000;106,103.600000000000,96.7000000000000,89.6000000000000,86.4000000000000,80.9000000000000,74,69.8000000000000,55.7000000000000,45.8000000000000,41.2000000000000;98,85.9000000000000,77.6000000000000,69.3000000000000,63.8000000000000,56.9000000000000,50.5000000000000,46,32.2000000000000,21.3000000000000,17.4000000000000;65.4000000000000,45.7000000000000,37.2000000000000,27.8000000000000,23.5000000000000,19.1000000000000,15.6000000000000,11.9000000000000,0,0,0;0,0,0,0,0,0,0,0,0,0,0]; %torque from table
rpm1out=[1000;1400;1700;1900;3300;3500;3700;4100;4700;4900;5200;5400]; %sample rpm
tr1out=[95.4929658551372;102.313891987647;101.110199140734;100.518911426460;115.749049521378;122.776670385176;129.044548452888;128.100320049574;121.905913857622;126.674342460896;128.548223266531;127.323954473516]; %sample torque
theta1out=interp2(rpm1,theta1,tr1,rpm1out,tr1out, 'spline'); %desire

Yazan
Yazan 2021-7-1
The function interp2 performs interpolation for 2D gridded data. It has the form Vq = interp2(X,Y,V,Xq,Yq), where X and Y contain the coordinates of the sample points. V contains the corresponding function values at each sample point. Xq and Yq contain the coordinates of the query points. Now, in your example, the 2D function tr1 is defined over rpm1 and theta1, but those two vectors have different sizes! You have stored 11 values in rpm1 and only 6 values in theta1. For interp2 to function properly, you should define the missing 5 theta1 values.

KSSV
KSSV 2021-7-1
编辑:KSSV 2021-7-1
rpm1=[1000,2000,2500,3000,3500,4000,4500,4750,5320,5800,6000]; %engine rpm from table
theta1=[100;80;60;40;20;1]; %throttle from table
tr1=[117.200000000000,123.600000000000,129.100000000000,132.100000000000,134.300000000000,137.200000000000,134.800000000000,135.200000000000,129,119.300000000000,113.100000000000;115.300000000000,121.900000000000,127.300000000000,131.100000000000,120.500000000000,125.500000000000,124.500000000000,125.100000000000,118.800000000000,109.600000000000,104.700000000000;106,103.600000000000,96.7000000000000,89.6000000000000,86.4000000000000,80.9000000000000,74,69.8000000000000,55.7000000000000,45.8000000000000,41.2000000000000;98,85.9000000000000,77.6000000000000,69.3000000000000,63.8000000000000,56.9000000000000,50.5000000000000,46,32.2000000000000,21.3000000000000,17.4000000000000;65.4000000000000,45.7000000000000,37.2000000000000,27.8000000000000,23.5000000000000,19.1000000000000,15.6000000000000,11.9000000000000,0,0,0;0,0,0,0,0,0,0,0,0,0,0]; %torque from table
rpm1out=[1000;1400;1700;1900;3300;3500;3700;4100;4700;4900;5200;5400]; %sample rpm
tr1out=[95.4929658551372;102.313891987647;101.110199140734;100.518911426460;115.749049521378;122.776670385176;129.044548452888;128.100320049574;121.905913857622;126.674342460896;128.548223266531;127.323954473516]; %sample torque
[X,Y] = meshgrid(rpm1,theta1) ;
plot(X,Y,'.r')
hold on
plot(rpm1out,tr1out,'*k')
theta1out=interp2(X,Y,tr1,rpm1out,tr1out); %desired throttle values for sample rpm and sample torque values
If you see, the values which you are trying to seek using interp2 are falling outside the domain. So this comes under extrapolation and results cannot be trusted.
  3 个评论
Stephen23
Stephen23 2021-7-1
@Aditya Gandhi: you accepted this answer. Does that mean that your problem is resolved?
Aditya Gandhi
Aditya Gandhi 2021-7-1
No Sir. My problem is not resolved. I am still trying to figure out what how this can be done.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by