Code covered by the BSD License  

Highlights from
min /max for arrays

  • max2(A); Function MAX2 finds value VALL of a largest element in an 2D array and
  • min2(A); Function MIN2 finds value VALL of a smallest element in an 2D array and
  • View all files

3.5

3.5 | 2 ratings Rate this file 10 Downloads (last 30 days) File Size: 1.92 KB File ID: #4709

min /max for arrays

by Sergei Koptenko

 

02 Apr 2004 (Updated 13 May 2005)

min max extension into array.

| Watch this File

File Information
Description

Gives minimum or maximum value and its indices [row column] for a 2D array. For a vector works same as regular min and max.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
27 Apr 2006 Amber Anderson

Perfect. Simple program that does exactly what it says it does.

22 Oct 2009 Jan Simon

Help existing, no H1-line, author and date mentioned, no check of inputs (fails for the empty matrix), program works.

Some ideas for improvements:
  [i,j]=find(A==-Inf); A(i,j)=NaN;
can be computed faster:
  A(A==-Inf)=NaN;
But I'd omit replacing -Inf completely, because there is no motivation to do this in a general function.

The exceptional handling of vectors is a drawback, because the user has to catch this case. With the following, the row and column indices are replied even for vectors and the empty matrix:
  [vall, L] = min(A(:)); s1 = size(A, 1);
  indd = [rem(L - 1, s1) + 1, floor(((L - 1) / s1) + 1];

Using the standard indentation scheme and just one command per line would increase the readability.

Please login to add a comment or rating.
Updates
13 May 2005

Added: check and replacement of +/-Inf (for instance as result of log10(0)operation) to NaN

Tag Activity for this File
Tag Applied By Date/Time
max Sergei Koptenko 22 Oct 2008 07:17:24
min Sergei Koptenko 22 Oct 2008 07:17:24
array Sergei Koptenko 22 Oct 2008 07:17:24
max2 Sergei Koptenko 22 Oct 2008 07:17:24
min2 Sergei Koptenko 22 Oct 2008 07:17:24
max2 Prabakaran K 24 May 2011 13:10:54

Contact us at files@mathworks.com