1

我有一个 2D 网格 (G= 250x250),其中只有大约 100 个点是已知的,其余的是未知的 (NaN)。我想调整这个矩阵的大小。我的问题是imresize不能在 MATLAB 中为我做这件事,因为它删除了我的已知值并且只给出了一个 NaN 矩阵。

有人知道可以为我做的方法吗?一个建议是使用插值方法(例如通过使用反距离加权),但我不确定它是否有效,甚至有没有更好的方法?

    G = NaN(250,250);
    a = ceil(rand(1,50)*250*250);
    b = ceil(rand(1,50)*250*250);
    G (a) = 1; G (b) = 0;
4

1 回答 1

2

这个怎么样:

% find the non-NaN entries in G
idx = ~isnan(G);

% find their corresponding row/column indices
[i,j] = find(idx);

% resize your matrix as desired, i.e. scale the row/column indices
i = ceil(i*100/250);
j = ceil(j*100/250);

% write the old non-NaN entries to Gnew using accumarray
% you have to set the correct size of Gnew explicitly
% maximum value is chosen if many entries share the same scaled i/j indices
% NaNs are used as the fill
Gnew = accumarray([i, j], G(idx), [100 100], @max, NaN);

如果 max 不适合您,您也可以为 accumarray 选择不同的累积函数。如果它不是您需要的,您可以将填充值从 NaN 更改为其他值。

于 2012-09-27T20:16:28.183 回答