Interpolation of missing matrix element
2 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to interpolate some missing data of my 3x3 matrix,
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
where 0s represent the missing value that I would like to interpolate to fill it in.
I read through interp1-3 command but not so sure on what to do to find a missing values
Please help!
0 个评论
采纳的回答
KSSV
2022-11-1
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN
M = fillmissing(M,'linear')
M = fillmissing(M','linear')'
1 个评论
DGM
2022-11-1
编辑:DGM
2022-11-1
Fillmissing() only interpolates/extrapolates columnwise. Since the center column has only a single value, extrapolation fails. While transposing and filling again will clean up the remaining holes, it still means that the center pixel has no influence over any of the filled values.
M = [1 0 1; 0 0 0; 0 1E6 0; 1 0 1];
M(M==0) = NaN;
M = fillmissing(M,'linear')
M = fillmissing(M','linear')'
If there were enough data in the center column to support the default extrapolation behavior, the results would be wildly different.
M = [1 0 1; 0 1E6 0; 0 1E6 0; 1 0 1];
M(M==0) = NaN;
M = fillmissing(M,'linear')
M = fillmissing(M','linear')'
Using fillmissing() seems like it would be valid for columnwise organized data, but if that were the case, would it still make sense to interpolate across columns?
更多回答(1 个)
DGM
2022-11-1
I'm sure there are multiple ways, and interpolation may depend on whether this is 2D data or a bunch of independent rows of data. Here are a few things.
I'm not familiar with using fillmissing(), but using it like this doesn't seem right. It fills the holes, but the center pixel has no influence over filling its neighbors.
% above solution
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN;
M = fillmissing(M,'linear');
M = fillmissing(M','linear')';
imshow(M,[38 44])
If you have IPT, you can use regionfill()
% inpaint with IPT regionfill()
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
mask = M==0;
M = regionfill(M,mask);
imshow(M,[38 44])
If you don't have IPT, you could use John's inpainting tool from the FEX:
% inpaint with inpaint_nans()
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN;
M = inpaint_nans(M);
imshow(M,[38 44])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!