How are these not already MATLAB functions?

EDIT: I have since been informed that you can concatenate multiple arrays together just by putting them inside braces []. Thus, you can use MATLAB’s built-in min and max functions by doing the following:

% assuming A and B are two arrays…
C = min([A B]);

You learn something new every day when you’re a novice in some language!

Nevertheless, I will keep my two functions implemented. The downside to using the above method is that it results in a full-on copy of the two vectors into a single vector. The problem with doing this is that:
1) It is slow!
2) It could result in a memory overflow if the arrays are large enough.

I have also updated my functions to handle matrices as well. Enjoy.

=============================================================================

I was at work today and needed to loop through a large amount of data in MATLAB. I was doing a diff between two arrays and needed to loop between it’s min and max values. Unless I suck at using Google, I couldn’t find any built-in MATLAB functions that return the smallest min of multiple arrays or the largest max of multiple arrays.

Here they are for your pleasure:

smallestMin

% SMALLESTMIN(X) The smallest component of all vector and/or matrix inputs.
%   SMALLESTMIN(X), where X is any number of vectors and/or matrices, is 
%   the smallest component present in any of these structures.  
%   SMALLESTMIN(X) is consistent with MATLAB's built-in MIN(X) for vectors
%   only!! SMALLESTMIN(X) for a matrix returns the equivalent of 
%   MIN(MIN(X)).  SMALLESTMIN accepts mixed inputs of vectors and matrices.
%   A matrix is defined as having exactly 2 dimensions.
%
%   VALID INPUTS: row and column vectors and 2-D matrices.  These can
%                 contain characters, complex numbers, and numerics.
%                 Logicals, doubles, singles, int8, uint8, int16, int32,
%                 and uint32 are also valid.
%   INVALID INPUTS: cell arrays, 64-bit signed and unsigned values,
%   structures, function handles, user classes, and java classes.
%
%   These lists may not be all-inclusive.
%
%   Ex 1: If A = [1 2 3 4] and B = [-1   then smallestMin(A,B) returns -1.
%                                    2
%                                    3
%                                    4]
%
%   Ex 2: If A = [1 2   and B = [5 6 7 8] then smallestMin(A,B) returns 1.
%                 3 4]
%
%   Author:  Brian A. Schrameck
%   Version: v0.1
%   Date:    07/15/2009
%   Email:   <a href="mailto:schrameckbrian+smallestMin@gmail.com">schrameckbrian+smallestMin@gmail.com</a>
%
%   See also min, max, isnumeric, and largestMax (available on the MATLAB
%   File Exchange).

function smallestVal = smallestMin (varargin)

smallestVal = 0;

if ( length(varargin) < 1 )
    error('At least 1 argument must be present!')
end

for i=1:length(varargin)
    % This will catch at least most of the bad stuff thrown at it.  It will
    % not catch uint64/int64, or function handles; probably some other
    % stuff too.
    if ( (~isvector(varargin{i}) && ndims(varargin{i}) ~= 2 ) || ...
            iscell(varargin{i}) )
        error('Argument %d is not a vector or 2D matrix!', i)
    end
    % We will error out here if we didn't catch something earlier, as min
    % will die.
    curMin = min(min(varargin{i}));
    if ( i == 1 )
        % First time through is always the min value.
        smallestVal = curMin;
    elseif ( curMin < smallestVal )
        % Compare against current smallest value.
        smallestVal = curMin;
    end
end
end

largestMax

% LARGESTMAX(X) The largest component of all vector and/or matrix inputs.
%   LARGESTMAX(X), where X is any number of vectors and/or matrices, is 
%   the largest component present in any of these structures.  
%   LARGESTMAX(X) is consistent with MATLAB's built-in MAX(X) for vectors
%   only!! LARGESTMAX(X) for a matrix returns the equivalent of 
%   MAX(MAX(X)).  LARGESTMAX accepts mixed inputs of vectors and matrices.
%   A matrix is defined as having exactly 2 dimensions.
%
%   VALID INPUTS: row and column vectors and 2-D matrices.  These can
%                 contain characters, complex numbers, and numerics.
%                 Logicals, doubles, singles, int8, uint8, int16, int32,
%                 and uint32 are also valid.
%   INVALID INPUTS: cell arrays, 64-bit signed and unsigned values,
%   structures, function handles, user classes, and java classes.
%
%   These lists may not be all-inclusive.
%
%   Ex 1: If A = [1 2 3 4] and B = [-1   then largestMax(A,B) returns 5.
%                                    2
%                                    3
%                                    5]
%
%   Ex 2: If A = [1 2   and B = [5 6 7 8] then largestMax(A,B) returns 8.
%                 3 4]
%
%   Author:  Brian A. Schrameck
%   Version: v0.1
%   Date:    07/15/2009
%   Email:   <a href="mailto:schrameckbrian+largestMax@gmail.com">schrameckbrian+largestMax@gmail.com</a>
%
%   See also max, min, isnumeric, and smallestMin (available on the MATLAB
%   File Exchange).

function largestVal = largestMax (varargin)

largestVal = 0;

if ( length(varargin) < 1 )
    error('At least 1 argument must be present!')
end

for i=1:length(varargin)
    % This will catch at least most of the bad stuff thrown at it.  It will
    % not catch uint64/int64, or function handles; probably some other
    % stuff too.
    if ( (~isvector(varargin{i}) && ndims(varargin{i}) ~= 2 ) || ...
            iscell(varargin{i}) )
        error('Argument %d is not a vector or 2D matrix!', i)
    end
    % We will error out here if we didn't catch something earlier, as max
    % will die.
    curMax = max(max(varargin{i}));
    if ( i == 1 )
        % First time through is always the max value.
        largestVal = curMax;
    elseif ( curMax > largestVal )
        % Compare against current largest value.
        largestVal = curMax;
    end
end
end