Find the zero array in the matrix and replace it with average of surrounding (adjacent) arrays.
Example:
A =
3 5 7 90 1
5 1 -1 0 2
1 2 3 4 70
23 1 2 3 5
Output is:
B=23.75;
Solution Stats
Problem Comments
5 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers43
Suggested Problems
-
How to find the position of an element in a vector without using the find function
2812 Solvers
-
4315 Solvers
-
Project Euler: Problem 6, Natural numbers, squares and sums.
2535 Solvers
-
393 Solvers
-
Create an index-powered vector
933 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I think you want to write A and not x:
assert(isequal(adjacent_averaging(A),B))
test case #2 and 3 should be corrected. Instead of x, it should be A
What elements do you consider the "surrounding arrays"?
Surrounding arrays apparently are the elements right above, below, left, and right the zero elements. Found out by reverse engineering. The x is still a mystery.
More tests please. A lot of solutions assume that 0 can't be in the first (or last) column.