- 积分
- 8348
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-2-23
- 最后登录
- 1970-1-1
|
发表于 2019-11-12 10:47:18
|
显示全部楼层
function value=find_nearpoint(x,y,z,xp,yp)
% x,y分别为插值前经纬度矩阵(或位置编号矩阵),z为插值前数据矩阵
% xp,yp分别为插值后经纬度矩阵(或位置编号矩阵)
if size(x,1)~=size(y,1) || size(x,1)~=size(z,1) || size(y,1)~=size(z,1) ||...
size(x,2)~=size(y,2) || size(x,2)~=size(z,2) || size(y,2)~=size(z,2)
error(message('MATLAB:find_nearpoint:please check x 、y and z,they must have same size'))
elseif size(xp,1)~=size(yp,1) || size(xp,2)~=size(yp,2)
error(message('MATLAB:find_nearpoint:please check xp and yp,they must have same size'))
end
if size(x,1)==1%转化为列向量
x=x';y=y';z=z';
end
if size(xp,1)==1
xp=xp';yp=yp';
end
value=zeros(size(xp,1),size(xp,2));
for i=1:size(xp,1)
for j=1:size(xp,2)
d=(x-xp).^2+(y-yp).^2;
dmin=min(sort(d(:)));
%%zz=find(d==dmin); zz为具有x维数信息的列向量,当x
%%y为位置矩阵时候,易得到多个数值,因此可采用下一种find方式
zz=find(d==dmin,1,'first');
value(i,j)=z(zz);
end
end
当有经纬度或位置信息的时候find_nearpoint里面有5个参数,若没有x,y,xp和yp的话,就只有z一个,修改很easy,我就不直接给你了 |
|