MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayFor 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)

34 correct solutions
30 incorrect solutions

Last solution submitted on Feb 20, 2014

2 Comments