24小时热门版块排行榜    

Znn3bq.jpeg
查看: 980  |  回复: 3

雨人007

银虫 (小有名气)

[求助] MATLAB 中有关griddata的计算原理,看不懂,求详解!

>>type griddata
function [xi,yi,zi] = gdatav4(x,y,z,xi,yi)
%GDATAV4 MATLAB 4 GRIDDATA interpolation

%   Reference:  David T. Sandwell, Biharmonic spline
%   interpolation of GEOS-3 and SEASAT altimeter
%   data, Geophysical Research Letters, 2, 139-142,
%   1987.  Describes interpolation using value or
%   gradient of value in any dimension.

xy = x( + y(*sqrt(-1);

% Determine distances between points
d = xy(:,ones(1,length(xy)));
d = abs(d - d.');
n = size(d,1);
% Replace zeros along diagonal with ones (so these don't show up in the
% find below or in the Green's function calculation).
d(1:n+1:numel(d)) = ones(1,n);

non = find(d == 0, 1);
if ~isempty(non),
  % If we've made it to here, then some points aren't distinct.  Remove
  % the non-distinct points by averaging.
  [r,c] = find(d == 0);
  k = find(r < c);
  r = r(k); c = c(k); % Extract unique (row,col) pairs
  v = (z(r) + z(c))/2; % Average non-distinct pairs
  
  rep = find(diff(c)==0);
  if ~isempty(rep), % More than two points need to be averaged.
    runs = find(diff(diff(c)==0)==1)+1;
    for i=1:length(runs),
      k = (c==c(runs(i))); % All the points in a run
      v(runs(i)) = mean(z([r(k);c(runs(i))])); % Average (again)
    end
  end
  z(r) = v;
  if ~isempty(rep),
    z(r(runs)) = v(runs); % Make sure average is in the dataset
  end

  % Now remove the extra points.
  z(c) = [];
  xy(c, = [];
  xy(:,c) = [];
  d(c, = [];
  d(:,c) = [];
  
  % Determine the non distinct points
  ndp = sort([r;c]);
  ndp(ndp(1:length(ndp)-1)==ndp(2:length(ndp))) = [];

  warning('MATLAB:griddata:NonDistinctPoints',['Averaged %d non-distinct ' ...
            'points.\n         Indices are: %s.'],length(ndp),num2str(ndp'))
end

% Determine weights for interpolation
g = (d.^2) .* (log(d)-1);   % Green's function.
% Fixup value of Green's function along diagonal
g(1:size(d,1)+1:numel(d)) = zeros(size(d,1),1);
weights = g \ z(;

[m,n] = size(xi);
zi = zeros(size(xi));
jay = sqrt(-1);
xy = xy.';

% Evaluate at requested points (xi,yi).  Loop to save memory.
for i=1:m
  for j=1:n
    d = abs(xi(i,j)+jay*yi(i,j) - xy);
    mask = find(d == 0);
    if ~isempty(mask), d(mask) = ones(length(mask),1); end
    g = (d.^2) .* (log(d)-1);   % Green's function.
    % Value of Green's function at zero
    if ~isempty(mask), g(mask) = zeros(length(mask),1); end
    zi(i,j) = g * weights;
  end
end

if nargout<=1,
  xi = zi;
end
回复此楼

» 猜你喜欢

想做的事情挡不住!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

acalephs

捐助贵宾 (著名写手)

哪不懂
2楼2014-12-25 15:34:41
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

雨人007

银虫 (小有名气)

引用回帖:
2楼: Originally posted by acalephs at 2014-12-25 15:34:41
哪不懂

我想知道V4怎样实现插值的,比如线性插值,是把与插值点靠近的两个数据直接连接,然后在直线上选取对应插值点的数据。V4是根据什么插值的
想做的事情挡不住!
3楼2014-12-26 10:07:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

acalephs

捐助贵宾 (著名写手)

引用回帖:
3楼: Originally posted by 雨人007 at 2014-12-26 10:07:04
我想知道V4怎样实现插值的,比如线性插值,是把与插值点靠近的两个数据直接连接,然后在直线上选取对应插值点的数据。V4是根据什么插值的...

参考文献应该有说明吧,其实我也不清楚。。。
4楼2015-01-13 20:01:38
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 雨人007 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 291求调剂 +9 关忆北. 2026-04-14 9/450 2026-04-16 13:49 by asdsyh1111
[考研] 300求调剂 +10 橙a777 2026-04-15 10/500 2026-04-16 12:50 by maoqinghuijz
[考研] 294求调剂 +11 淡然654321 2026-04-15 11/550 2026-04-16 10:23 by beilsong20
[考研] 求助调剂,跨调 +19 X十甫寸Y 2026-04-11 20/1000 2026-04-15 21:18 by cuisz
[考研] 085404 22408 309分求调剂 +9 lzmk 2026-04-14 10/500 2026-04-15 20:02 by 学员JpLReM
[考研] 一志愿中国科学院上海有机所,有机化学356分找调剂 +12 Nadiums 2026-04-09 13/650 2026-04-14 17:54 by lhj2009
[考研] 335求调剂 +19 想上岸呀!! 2026-04-12 21/1050 2026-04-14 16:23 by Art1977
[考研] 一志愿沪9,326求生物学调剂 +10 刘墨墨 2026-04-13 10/500 2026-04-14 15:16 by zs92450
[考研] 105500药学求调剂 +4 x_skys 2026-04-12 4/200 2026-04-14 13:37 by rndfc
[考研] 085408光电信息工程专硕355一志愿长春光机所调剂 +6 王ymaa 2026-04-13 13/650 2026-04-14 11:33 by 王ymaa
[考研] 2026硕士调剂_能动_河南农业大学 +4 河南农业大学-能 2026-04-12 4/200 2026-04-13 22:01 by bljnqdcc
[基金申请] 2026 WR青拔 +3 冬日阳光CAS 2026-04-09 6/300 2026-04-13 18:40 by liuchb715
[考研] 生物学调剂 +11 小冉要努力 2026-04-10 13/650 2026-04-13 11:46 by 电化学及催化
[考研] 2本,初试303,0860求调剂 +6 floriea 2026-04-12 8/400 2026-04-12 18:13 by zhouxiaoyu
[考研] 277 数一104,学硕,求调剂 +21 瓶子PZ 2026-04-09 23/1150 2026-04-11 23:12 by labixiaoqiao
[考研] 270求调剂 +14 杨乐369 2026-04-11 14/700 2026-04-11 20:16 by 蓝云思雨
[考研] 263能源动力专硕求调剂 +3 加大号饭盒袋 2026-04-10 3/150 2026-04-10 22:23 by 286640313
[考研] 083200 305分 求二轮调剂 不接受跨专业 +9 Claireyyyy 2026-04-09 10/500 2026-04-10 21:21 by Claireyyyy
[考研] 298求调剂 +13 钉叮咚冬瓜 2026-04-09 13/650 2026-04-10 15:49 by jiajinhpu
[考研] 085601初试330分找调剂 +10 流心奶黄包l 2026-04-09 10/500 2026-04-10 08:14 by Sammy2
信息提示
请填处理意见