Code covered by the BSD License  

Highlights from
Maximum Or Minimum for N Dimension Array

4.0

4.0 | 3 ratings Rate this file 8 Downloads (last 30 days) File Size: 3.45 KB File ID: #15975

Maximum Or Minimum for N Dimension Array

by Serhend Arvas

 

17 Aug 2007 (Updated 18 Aug 2007)

These functions return the subscripts of the maximum or minimum in an Array

| Watch this File

File Information
Description

%maxNsarvas N-D Array Maximum With Subscript Output
%
% X = MAXN(A) returns the maximum value found as the first element followed
% by the subscripts of A. No knowledge about the size of A is needed prior
% to use.
%
% X = [maximum(A) sub1 sub2 sub3 . . . subN];
%
% If the maximum appears more than once (M times), each row contains
% the maximum followed by a set of subscripts that correspond to it.
%
% X = [maximum(A) sub1_1 sub2_1 sub3_1 . . . subN_1]
% [maximum(A) sub1_2 sub2_2 sub3_2 . . . subN_2]
% :
% [maximum(A) sub1_M sub2_M sub3_M . . . subN_M]
%
% This code uses D.C. Hanselman's MAXN routine.
% August 2007
% Serhend Arvas, Syracuse University.

%
%minNsarvas N-D Array Minimum With Subscript Output
%
% X = MINN(A) returns the minimum value found as the first element followed
% by the subscripts of A. No knowledge about the size of A is needed prior
% to use.
%
% X = [minimum(A) sub1 sub2 sub3 . . . subN];
%
% If the minimum appears more than once (M times), each row contains
% the minimum followed by a set of subscripts that correspond to it.
%
% X = [minimum(A) sub1_1 sub2_1 sub3_1 . . . subN_1]
% [minimum(A) sub1_2 sub2_2 sub3_2 . . . subN_2]
% :
% [minimum(A) sub1_M sub2_M sub3_M . . . subN_M]
%
% This code uses D.C. Hanselman's MINN routine.
% August 2007
% Serhend Arvas, Syracuse University.
%
% See also maxNsarvas

Acknowledgements
This submission has inspired the following:
MIN2, MAX2
MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
22 Aug 2007 Jos x@y.z

Poorly coded, with an unnecessary loop and even an ugly eval. Better use ind2sub and an intermediate cell array:
 
% some data
  A = ceil(10*rand(3,2,4,3,5,2)) ;
  A(2,1,3,2,4,2) = 99 ;
  A(3,2,2,1,3,1) = 99 ;
% the engine
  mxA = max(A(:)) ;
  idx0 = find(A == mxA) ;
  clear idx % not necessary inside a function
  [idx{1:ndims(A)}] = ind2sub(size(A),idx0) ;
  idx = cat(2,idx{:})

22 Aug 2007 Jos x@y.z

I intended to give this a 2-star rating

28 Aug 2007 s a

(About the code written by Jos x@y.z)
The code does work. It IS more elegantly written. Why not post it as a function?

18 Jan 2009 Sadik  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
maximum Serhend Arvas 22 Oct 2008 09:23:24
max Serhend Arvas 22 Oct 2008 09:23:24
min Serhend Arvas 22 Oct 2008 09:23:24
minimum Serhend Arvas 22 Oct 2008 09:23:24
nd Serhend Arvas 22 Oct 2008 09:23:24
dimension Serhend Arvas 22 Oct 2008 09:23:24
array Serhend Arvas 22 Oct 2008 09:23:24
dimensional Serhend Arvas 22 Oct 2008 09:23:24

Contact us at files@mathworks.com