For this challenge you get two inputs: a matrix A and an integer value n. Your function should return a Matrix B of the same size as A with integer values. Thereby, the entry B(i,j) counts the occurrence of lower values in the neighborhood A(i-n:i+n,j) (column wise), while symmetric boundary conditions (A(i<1,j) == A(-i+1,j) should be used (compare to padarray('symmetric')). For example,
assume n to be 2 and a matrix A containing double values, e.g.
A =
0.3147 -0.4025 -0.3424 -0.3581 0.1557 0.2577 0.2060
0.4058 -0.2215 0.4706 -0.0782 -0.4643 0.2431 -0.4682
-0.3730 0.0469 0.4572 0.4157 0.3491 -0.1078 -0.2231
0.4134 0.4575 -0.0146 0.2922 0.4340 0.1555 -0.4538
0.1324 0.4649 0.3003 0.4595 0.1787 -0.3288 -0.4029
then, your function should return
B =
2 1 1 1 3 4 4
3 2 4 2 0 2 0
0 2 3 3 3 1 3
4 2 0 1 4 3 1
2 4 3 4 1 1 3
Explanation: Consider the value -0.3730 in the first column of A. The two entries above and below are all bigger and thus, the corresponding entry in B is 0. However, the entry 0.4134 is bigger than its neighbors (symmetric boundary condition) and thus, the corresponding entry in B is 4. You can assume that n<=size(A,1)
Solution Stats
Problem Comments
6 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers26
Suggested Problems
-
3735 Solvers
-
The Goldbach Conjecture, Part 2
2413 Solvers
-
Find common elements in matrix rows
2713 Solvers
-
498 Solvers
-
16291 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Is the B matrix described above correct?
no, I believe the first and last rows should read [1 0 0 0 2 3 3] and [1 3 2 3 0 0 2], respectively
Is the test suite correct now? An old problem though...
Hello Rifat, I've solved this one recently, and it seems to be ok.
The test suite has been updated and solutions have been rescored.
The example given above is incorrect for B.
See Case Test 1 for the correct B example.
B = [1 0 0 0 2 3 3;...
3 2 4 2 0 2 0;...
0 2 3 3 3 1 3;...
4 2 0 1 4 3 1;...
1 3 2 3 0 0 2]