📄 chazhi.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%插值
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%一维插值
year = 1900:10:2010;
product = [75.995, 91.972, 105.711, 123.203, 131.669,...
150.697, 179.323, 203.212, 226.505, 249.633, 256.344, 267.893];
p2005 = interp1(year,product,1950)
x = 1900:1:2010;
y1 = interp1(year,product,x,'cubic'); %三次函数插值
y2 = interp1(year,product,x,'nearest'); %最近邻点插值,直接完成计算
y3 = interp1(year,product,x,'linear'); %线性插值(缺省方式),直接完成计算
y4 = interp1(year,product,x,'spline'); %三次样条函数插值
subplot(2,2,1),plot(year,product,'o',x,y1),title('cubic三次函数插值');
subplot(2,2,2),plot(year,product,'o',x,y2),title('nearest最近邻点插值');
subplot(2,2,3),plot(year,product,'o',x,y3),title('linear线性插值');
subplot(2,2,4),plot(year,product,'o',x,y4),title('spline三次样条函数插值');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%二维插值
x = 1:6; y = 1:4; %给出自变量
t = [12 10 11 11 13 15;16 22 28 35 27 20;...
18 21 26 32 28 25;20 25 30 33 32 30]; %注意t的维数和x,y的维数之间的关系
figure;
subplot(2,3,1),mesh(x,y,t),title('值前的温度分布图'); %画出插值前的温度分布图
x1 = 1:0.1:6; %将x细化为51个点
y1 = 1:0.1:4; %将x细化为31个点
[x2,y2] = meshgrid(x1,y1); %产生51行51列网络数据点,这一步不可省
t1 = interp2(x,y,t,x2,y2,'cubic');
t2 = interp2(x,y,t,x2,y2,'nearest');
t3 = interp2(x,y,t,x2,y2,'linear');
t4 = interp2(x,y,t,x2,y2,'spline');
subplot(2,3,2),mesh(x1,y1,t1),title('cubic三次函数插值');
subplot(2,3,3),mesh(x1,y1,t2),title('nearest最近邻点插值');
subplot(2,3,4),mesh(x1,y1,t3),title('linear线性插值');
subplot(2,3,5),mesh(x1,y1,t4),title('spline三次样条函数插值');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%三维数据插值
[x,y,z,v] = flow(20); %flow是MATLAB提供的水下射流速度数据
[xx,yy,zz] = meshgrid(0.1:0.25:10, -3:0.25:3, -3:0.25:3);
vv = interp3(x,y,z,v,xx,yy,zz);
shading interp %用线性插值法处理图像颜色的浓淡
colormap cool %青红浓淡色图
%不知道为什么显示不了图
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -