1
votes

I have an array with dimensions (517,462,399). I would like to obtain a matrix of size (517,462). Each entry of the matrix (i,j) is the maximum value of the array divided by the sum of the other values. That is, to get the (1,1) entry, we first compare the array entries (1,1,1),(1,1,2)...(1,1,399) and then we divide the maximum value by the sum of the remaining 398 entries.

1
Did you read the documentation for max and sum?Daniel
yes i did but i could not find how to do it.mohamed

1 Answers

4
votes

This relatively easy to achieve. Just apply the max and sum functions over the third dimension. The division of the two results has to be made element-wise with the . before the operator.
Here the code:

maxval = max(x,[],3);
result = (sum(x,3)-maxval) ./ maxval;

Note that the max-function needs an empty second argument here, because the third argument indicates the dimension.