MATLAB: Max and min value of matrix

gridmaxminvalue

I have AB matrix that contains 3000×2000 grids data.
AB =
(1,1) (1,2) (1,3) (1,4) ... (1,3000)
(2,1) (2,2) (2,3) (2,4) ... (2,3000)
(3,1) (3,2) (3,3) (3,4) ... (3,3000)
(4,1) (4,2) (4,3) (4,4) ... (4,3000)
(5,1) (5,2) (5,3) (5,4) ... (5,3000)
...
...
...
(2000,1)
I want to calculate (MAX-MIN) value for each 3×5 grids in matrix AB
For Example :
If target grid is (3,2), I use 15 grids data (1~5,1~3) for calculation of MAX and MIN.
And if MAX is (1,1) and MIN is (2,3), then (MAX-MIN) at (3,2) is ((1,1)-(2,3)).
In the same way, if target grid is (3,3), I use (1~5,2~4).
Can you help me to make automatic script to calculate this??

Best Answer

  • blockproc might do what you want:
    >> X = rand(3000,2000);
    >> Xmax = blockproc(X,[3,5],@(s)max(s.data(:)));
    >> Xmin = blockproc(X,[3,5],@(s)min(s.data(:)));
    >> Xdif = Xmax - Xmin;