Returns the value of the element with the largest abs value in the input matrix 'A'. Input 'A' must be numeric, but can be any size and shape.
This is useful because it eliminates iterating through all the dimensions of a matrix.
A=[-5 3 2 3; 3 2 1 4];
absmax(A) will return -5
absmax(A) will return 643
Jan Simon's solution is more efficient.
W. Owen Brimijoin's solution returns a matrix when there is more than one max value.
Even more efficient than W.Owen Brimijoin's suggestion:
[dummy, index] = max(abs(A(:));
result = A(index);
Linear indexing beats the logical indexing here.
What about this alternate (and arguably simpler) means of solving the problem:
Hooray for logical indexing!
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.