Problem 319. Biggest Value in the (Neighbor)Hood
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
-
5 Comments
Show
2 older comments
Venu Lolla
on 14 Feb 2012
Is the B matrix described above correct?
Alfonso Nieto-Castanon
on 15 Feb 2012
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
rifat
on 5 Feb 2015
Is the test suite correct now? An old problem though...
Jan Orwat
on 5 Feb 2015
Hello Rifat, I've solved this one recently, and it seems to be ok.
Dyuman Joshi
on 21 Feb 2023
The test suite has been updated and solutions have been rescored.
Solution Comments
Show commentsProblem Recent Solvers25
Suggested Problems
-
1242 Solvers
-
Project Euler: Problem 7, Nth prime
1427 Solvers
-
Convert Hard Drive marketing sizes to actual data sizes
68 Solvers
-
360 Solvers
-
Sum the entries of each column of a matrix which satisfy a logical condition.
162 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!