Max and Min of n-dimensional Matrices

Determines the max / min value and its index position of an n-dimensional matrix
472 Downloads
Updated 8 Jan 2014

View License

Determines the minimum / maximum value and its index of an n-dimensional
matrix. E.g., for a 2D-Matrix x and y position of the min / max value are
returned, for a 3D-Matrix x, y and z position of min / max value are returned.

Syntax: [v,idx] = minN(A) / [v,idx] = minN(A)

Inputs:
A - the matrix of which the minimum / maximum value shall be found

Outputs:
v - the minimum / maximum value of A
idx - the index of v in matrix A

Example:
A(:,:,1) = [1,1,2;1,1,1;1,1,1];
A(:,:,2) = [1,1,1;1,1,1;1,1,1];
A(:,:,3) = [1,1,1;1,1,1;0,1,1];

[v1,idx1] = minN(A);
[v2,idx2] = maxN(A);

% v1 = 0, and idx1 = [3,1,3]
% v2 = 2, and idx2 = [1,3,1]
% it is A(3,1,3) = 0
% it is A(1,3,1) = 2

Cite As

Christopher (2024). Max and Min of n-dimensional Matrices (https://www.mathworks.com/matlabcentral/fileexchange/44758-max-and-min-of-n-dimensional-matrices), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Elementary Math in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.1.0.0

Code simplification suggested by Jos (see comments) integrated.

1.0.0.0