I have a matrix containing a set of points:
[
100,100,40,50,30,
30,100,20,20,30,
10,20,45,30,22,
102,200,10,0,10
10,20,20,30,40
]
Is there a way we can retrieve a directional gradient (vector) from this matrix? The vector should be pointing toward the region that contains higher values. As for this example, as you can see, the values that are greater than 100 are mostly toward the left, therefore we can estimate that the vector maybe pointing leftward from right.
I am looking for a formula that is flexible enough such that, even if we change the size of the matrix, we would be able to compute a directional gradient.
My apologies if I am not using the right term for directional gradient, as my math knowledge only goes as far as calculus 2.
EDIT 1: Each row represent an increasing value of y. At the first row, y=1, and at the last row, y=5. Each column represents an increasing value of x. At first column x=1, and last column x=5.
You can use standard finite difference methods to estimate the derivative in each direction, and therefore determine the gradient. So for example, the gradient at $(3,3)$ can be estimated component-wise with $$\frac{\partial f(x,y)}{\partial x} \approx \frac{f(x+1,y)-2f(x,y)+f(x-1,y)}{1^2}$$ $$\frac{\partial f(x,y)}{\partial y} \approx \frac{f(x,y+1)-2f(x,y)+f(x,y-1)}{1^2}$$
which could be an appropriate algorithm in the interior. So $f_x(3,3)=-20$, and $f_y(3,3)=-7.5$ so the gradient is given by these derivatives as coefficients $\nabla f=-20 \hat{i}-7.5\hat{j}$.
On the boundary, you will have to use something simpler, since some of the above terms will be missing: for example, at $(1,1)$, you can use $$\frac{\partial f(x,y)}{\partial x} \approx \frac{f(x+1,y)-f(x,y)}{1}$$ $$\frac{\partial f(x,y)}{\partial y} \approx \frac{f(x,y+1)-f(x,y)}{1}$$