Pick up the eighth day of MATLAB
Matlab
One-dimensional linear interpolation
One-dimensional interpolation command
%x:原始数据(自变量)n维向量
%v:原始数据(函数值)n维向量
%xq:插值(自变量)可以使一个点,也可以是向量
%vq:插值结果(函数值)
vq = interp1(x,v,xq)
vq = intterp1(x,v,xq,method)
method
The 2014a version of matlab currently has these methods:
Example 1-Interpolation method:
The implementation script code is as follows:
production = [75.995 ... .... ..] %此处省了,实则是产量的值
years = 1900:10:2010; %设置年份区间
x = 1900:2010;
p_res = interp1(years,production,x,'spline')
plot(years,production,'o',x,p_res)
Run to get a continuous line.
Example 2-Interpolation method:
The implementation script code is as follows:
x = 0:2:24;
y = [....] %温度的值
% 注意:x和y的维度要一样,形成一一对应关系
x1 = 0:1/3600:24 %单位化成秒,增量为1s
strmethod={
'nearest',...} %方法
strlb={
'{a}method=nearest',...} %对应上方的方法
for i=1:6
y1 = interp1(x,y,x1,strmethod{
i});
subplot(3,2,i) %切割出3*2张图
plot(x,y,'ro',x1,y1,'b''linewith',1.5)
xlabel(strlb)
end
The effect is as follows: