Interpolation of missing matrix element

2 ビュー (過去 30 日間)
PetronasAMG
PetronasAMG 2022 年 11 月 1 日
編集済み: DGM 2022 年 11 月 1 日
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!

採用された回答

KSSV
KSSV 2022 年 11 月 1 日
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN
M = 3×3
43.1300 NaN 42.8800 NaN 39.3200 NaN 41.8100 NaN 43.2700
M = fillmissing(M,'linear')
M = 3×3
43.1300 NaN 42.8800 42.4700 39.3200 43.0750 41.8100 NaN 43.2700
M = fillmissing(M','linear')'
M = 3×3
43.1300 43.0050 42.8800 42.4700 39.3200 43.0750 41.8100 42.5400 43.2700
  1 件のコメント
DGM
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 = 4×3
1 NaN 1 1 NaN 1 1 1000000 1 1 NaN 1
M = fillmissing(M','linear')'
M = 4×3
1 1 1 1 1 1 1 1000000 1 1 1 1
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 = 4×3
1 1000000 1 1 1000000 1 1 1000000 1 1 1000000 1
M = fillmissing(M','linear')'
M = 4×3
1 1000000 1 1 1000000 1 1 1000000 1 1 1000000 1
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
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])

カテゴリ

Help Center および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by