Does fillmissing2 produce identical results for a matrix and its transposed version?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 20 Okt. 2025 um 0:00
Beantwortet: MathWorks Support Team
am 20 Okt. 2025 um 23:23
I have encountered an issue regarding the behavior of the "fillmissing2" function. Specifically, I expected that filling missing values in a 2D matrix and filling missing values in its transposed version (followed by transposing it back) would produce identical results. However, in practice, the results differ.
Akzeptierte Antwort
MathWorks Support Team
am 20 Okt. 2025 um 0:00
The discrepancy arises due to the way the "nearest" method in fillmissing2 determines which value to use when multiple neighboring elements are equally close to a missing value. Specifically, the function selects the neighbor with the largest Linear Index.
In MATLAB, linear indices are assigned in column-major order. For the following matrix:
A = 1 2 3
4 NaN 6
7 8 9
the linear indices for each element are as follows:
A(1,1): 1
A(2,1): 2
A(3,1): 3
A(1,2): 4
A(2,2): 5
A(3,2): 6
A(1,3): 7
A(2,3): 8
A(3,3): 9
When filling the NaN at A(2,2), the nearest valid neighbors are 4 (A(2,1), index 2), 2 (A(1,2), index 4), 8 (A(3,2), index 6), and 6 (A(2,3), index 8). Among these, A(2,3) has the largest Linear Index (8), so its value (6) is used to fill the missing entry. The result is:
>> fillmissing2(A, 'nearest')
ans =
1 2 3
4 6 6
7 8 9
However, when the matrix is transposed, the arrangement and thus the linear indices of the elements change. This can alter which neighbor has the largest Linear Index, leading to different results after filling and transposing back. Therefore, fillmissing2 does not guarantee identical results for a matrix and its double-transposed version, regardless of the method used. As a workaround, avoid relying on transposition symmetry when using fillmissing2 for missing value interpolation.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!