How can I find all zeros in a 2d matrix and change those values by interpolating with the closest available values ?

5 次查看(过去 30 天)
For example, A=

采纳的回答

Image Analyst
Image Analyst 2017-6-8
You could use regionfill(), if you have the Image Processing Toolbox, to do it in a single line of code:
outputArray = regionfill(inputArray, inputArray == 0);

更多回答(1 个)

Walter Roberson
Walter Roberson 2017-6-7
[gr, gc, gv] = find(A);
F = scatteredInterpolant(gr, gc, gv);
[br, bc] = find(~A);
replacements = F(br, bc);
A( sub2ind(size(A), br, bc) ) = replacements;

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by