使用 MATLAB 进行稀疏矩阵插值
如果我有一个像这样的矩阵,
A = [1 2; 3 4];
我可以使用 interp2 像这样对其进行插值
newA = interp2(A,2);
,然后得到一个 5x5 插值矩阵。
但是,如果我有一个像这样的矩阵怎么办:
B = zeros(20);
B(3,2) = 5;
B(17,4) = 3;
B(16, 19) = 2.3;
B(5, 18) = 4.5;
我将如何插入(或填充空白)这个矩阵。我研究过 interp2 和 TriScatteredInterp 但这些似乎都不完全符合我的需求。
If I have a matrix like this
A = [1 2; 3 4];
I can use interp2 to interpolate it like this
newA = interp2(A,2);
and I get a 5x5 interpolated matrix.
But what if I have a matrix like this:
B = zeros(20);
B(3,2) = 5;
B(17,4) = 3;
B(16, 19) = 2.3;
B(5, 18) = 4.5;
How would I interpolate (or fill-in the blanks) this matrix. I've looked into interp2 as well as TriScatteredInterp but neither of these seem to fit my needs exactly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个好的解决方案是使用我的 inpaint_nans。只需提供不存在信息的 NaN 元素,然后使用 inpaint_nans。它将对 NaN 元素进行插值,填充它们以与数据点平滑一致。
编辑:
对于那些对inpaint_nans是否可以处理更复杂的表面感兴趣的人,我曾经拍过一张数字化的莫奈绘画(见左侧,然后通过删除随机 50% 的像素来破坏它。最后,我应用 inpaint_nans 来查看是否可以很好地恢复图像。右侧图像是修复后的图像。虽然分辨率较低,恢复的图像是一个不错的恢复
作为另一个示例,请尝试以下操作:
现在,删除该数组中大约 7/8 的元素,并
使用 z- 进行恢复。轴具有不同的缩放比例,因为边缘周围存在 +/-1 上方和下方的微小变化,但除此之外,后一个表面是一个很好的近似值
。 " alt="在此输入图像描述">
A good solution is to use my inpaint_nans. Simply supply NaN elements where no information exists, then use inpaint_nans. It will interpolate for the NaN elements, filling them in to be smoothly consistent with the data points.
Edit:
For those interested in whether inpaint_nans can handle more complex surfaces, I once took a digitized Monet painting (seen on the left hand side, then corrupted it by deleting a random 50% of the pixels. Finally, I applied inpaint_nans to see if I could recover the image reasonably well. The right hand image is the inpainted one. While the resolution is low, the recovered image is a decent recovery.
As another example, try this:
Now, delete about 7/8 of the elements of this array, replacing them with NaNs.
Recover using inpainting. The z-axis has a different scaling because there are minor variations above and below +/-1 around the edges, but otherwise, the latter surface is a good approximation.