clear all;
clc;
%% 导入excel文件,数据去找发动机的map,trucksim中
niuju=xlsread('\Engine1.csv','B2:K18');
jieqimen=xlsread('\Engine1.csv','B1:K1');
zhuansu=xlsread('\Engine1.csv','A2:A18');
%写成节气门、扭矩、转速一一对应的关系
j=1;
for i=1:length(jieqimen)
Torque(:,i)=niuju(:,i);
speed(:,i)=zhuansu;
Throttle(:,i)=ones(length(zhuansu),1)*jieqimen(j);
j=j+1;
end
%合并
To=Torque(:,1)';
s=speed(:,1)';
Th=Throttle(:,1)';
for i=2:length(jieqimen)
To=[To,Torque(:,i)'];
Th=[Th,Throttle(:,i)'];
s=[s,speed(:,i)'];
end
%% 把转矩、转速,节气门开度写成一个非常长的行
F=scatteredInterpolant(To',s',Th');
%% 进行插值
maxT=max(To);
minT=min(To);
Tu=minT:10:maxT;
su=min(s):100:max(s);
table=zeros(length(Tu),length(su));
for i=1:length(Tu)
for j=1:length(su)
table(i,j)=F(Tu(i),su(j));
if table(i,j)>=1
table(i,j)=1;
elseif table(i,j)<=0
table(i,j)=0;
else
table(i,j)=table(i,j);
end
end
end
%% 绘图
figure
[n,T]=meshgrid(su,Tu);
mesh(n,T,table);
数据