SRAM overflow

dc42:
Since the data you are storing in the arrays comprises 10-bit values from analogRead, you could pack 2 readings into 3 bytes (instead of 4 bytes), reducing the memory requirement by 25%. Or you could pack 3 readings into 4 bytes (instead of 6 bytes), reducing the memory requirement by 33%.

Depending on the largest variation of minval, if it is less than +-128, you can just store the averago of minval and have a matrix of just variations. You reduce 50% memory cost. Same goes with maxval.