File Exchange

image thumbnail


version 1.0 (1.27 KB) by

Returns the value of the element with the largest absolute value in the input matrix.

1 Download


View License

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

Comments and Ratings (3)

Jan Simon's solution is more efficient.

W. Owen Brimijoin's solution returns a matrix when there is more than one max value.

Jan Simon

Jan Simon (view profile)

Even more efficient than W.Owen Brimijoin's suggestion:

  [dummy, index] = max(abs(A(:));
  result = A(index);

Linear indexing beats the logical indexing here.

Owen Brimijoin

What about this alternate (and arguably simpler) means of solving the problem:


Hooray for logical indexing!

MATLAB Release
MATLAB 8.1 (R2013a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video