Hi community,
I have several matrices containing 0s, 1s and NaNs. Most of elements are 0s and NaNs, and in less amount there are 1s.
Regarding 1s, I need to replace them to NaNs if they are surrounded in 8 directions by NaNs. These 1s are not single 1s, but can be also be connected in 8-directions.
For example, considering this matrix:
[NaN NaN NaN NaN 1 0;NaN 1 NaN NaN 1 0;NaN NaN 1 NaN 1 0;NaN NaN 1 NaN NaN 0;NaN NaN NaN NaN NaN 0]
The expected output would be:
[NaN NaN NaN NaN 1 0;NaN NaN NaN NaN 1 0;NaN NaN NaN NaN 1 0;NaN NaN NaN NaN NaN 0;NaN NaN NaN NaN NaN 0]
Thank you very much for your help!!
Best Answer