如何在matlab中进行棋盘插值?
我有两个矩阵 A
和 B
,其中包含形式为棋盘/棋盘式网格的值
AxAxAxAx...
xBxBxBxB...
AxAxAxAx...
xBxBxBxB...
...........
...........
,其中 x
表示我尚不知道的值想要(线性)插值。实现这一目标的最简单方法是什么?
首先可能是
C = zeros(size(A)+size(B));
C(1:2:end,1:2:end) = A;
C(2:2:end,2:2:end) = B;
获得上述矩阵。现在我可以遍历所有剩余点并取所有直接邻居的平均值,因为1)matlab中的for
循环很慢,2)当然有一种方法可以使用< code>interp2,尽管这似乎需要类似 meshgrid
的网格。那么,这可以更容易/更快地完成吗?
I have two matrices A
and B
containing values for a checkerboard/chessboard-like grid of the form
AxAxAxAx...
xBxBxBxB...
AxAxAxAx...
xBxBxBxB...
...........
...........
Where x
represents values not yet known which I want to (linearly) interpolate. What's the easiest way to achieve this?
First thing is probably
C = zeros(size(A)+size(B));
C(1:2:end,1:2:end) = A;
C(2:2:end,2:2:end) = B;
to obtain aforementioned matrix. Now I could loop through all remaining points and take the average of all direct neighbours, for 1) for
loops in matlab are slow and 2) there's certainly a way to use interp2
, though that seems to require a meshgrid
-like grid. So, can this be done easier/faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

感谢 woodchips 的回答在这里我找到了他的inpaint_nans,解决办法确实很简单:
Thanks to woodchips' answer here I found his inpaint_nans, the solution is indeed simple: