There might be faster ways to the result, but this would work:
ILArray<double> E = counter(5, 5);
E is now:
<Double> [5,5]
[0]: 1 6 11 16 21
[1]: 2 7 12 17 22
[2]: 3 8 13 18 23
[3]: 4 9 14 19 24
[4]: 5 10 15 20 25
Copy to a new variable, modify the diagonal and acquire the maximum value:
// make a copy of E
ILArray<double> maxE = E.C;
// set diagonal of the copy to smallest value
maxE[r(0,maxE.S[0]+1,numel(maxE)-1)] = minall(maxE);
// compute the max value
maxE = maxall(maxE);
>maxE
<Double> 24
Note, the code is expected to get executed in the context of a subclass of ILMath, as usual.