24小时热门版块排行榜    

查看: 949  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 【考研调剂】化学专业 281分,一志愿四川大学,诚心求调剂 +6 吃吃吃才有意义 2026-03-19 6/300 2026-03-20 10:47 by 尽舜尧1
[考研] 265求调剂 +8 梁梁校校 2026-03-19 8/400 2026-03-20 09:08 by 每天只摆一小会
[考研] 329求调剂 +6 想上学吖吖 2026-03-19 6/300 2026-03-20 09:00 by 每天只摆一小会
[考研] 0817 化学工程 299分求调剂 有科研经历 有二区文章 +20 rare12345 2026-03-18 20/1000 2026-03-20 08:42 by 无际的草原
[考研] 0703化学调剂 +10 妮妮ninicgb 2026-03-15 14/700 2026-03-19 22:59 by 学员8dgXkO
[考研] 288求调剂,一志愿华南理工大学071005 +5 ioodiiij 2026-03-17 5/250 2026-03-19 18:22 by zcl123
[考研] 一志愿西安交通大学材料工程专业 282分求调剂 +5 枫桥ZL 2026-03-18 7/350 2026-03-19 14:52 by 功夫疯狂
[考研] 材料与化工求调剂 +7 为学666 2026-03-16 7/350 2026-03-19 14:48 by 尽舜尧1
[考研] 324分 085600材料化工求调剂 +3 llllkkkhh 2026-03-18 3/150 2026-03-19 14:22 by houyaoxu
[考研] 材料考研调剂 +3 xwt。 2026-03-19 3/150 2026-03-19 11:22 by w沐阳w
[考研] 材料工程专硕调剂 +5 204818@lcx 2026-03-17 6/300 2026-03-18 22:55 by 204818@lcx
[考研] 344求调剂 +6 knight344 2026-03-16 7/350 2026-03-18 20:13 by walc
[考研] 0854,计算机类招收调剂 +3 胡辣汤放糖 2026-03-15 6/300 2026-03-18 12:09 by 上岸上岸……..
[考研] 293求调剂 +11 zjl的号 2026-03-16 16/800 2026-03-18 08:10 by zhukairuo
[考研] 考研求调剂 +3 橘颂. 2026-03-17 4/200 2026-03-17 21:43 by 有只狸奴
[考研] 070303 总分349求调剂 +3 LJY9966 2026-03-15 5/250 2026-03-16 14:24 by xwxstudy
[考研] 277材料科学与工程080500求调剂 +3 自由煎饼果子 2026-03-16 3/150 2026-03-16 14:10 by 运气yunqi
[考研] 327求调剂 +6 拾光任染 2026-03-15 11/550 2026-03-15 22:47 by 拾光任染
[考研] 080500,材料学硕302分求调剂学校 +4 初识可乐 2026-03-14 5/250 2026-03-14 21:08 by peike
[硕博家园] 085600 260分求调剂 +3 天空还下雨么 2026-03-13 5/250 2026-03-13 18:46 by 天空还下雨么
信息提示
请填处理意见