1

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.

2
  • 2
    Did you read the documentation for max and sum? Commented Jul 7, 2015 at 19:41
  • yes i did but i could not find how to do it. Commented Jul 7, 2015 at 19:45

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

but the sum should exclude the maximum value.
@mohamed: Just subtract the maximum value before the division. I edited my answer accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.