min - Minimum elements of array (2024)

Table of Contents
Syntax Description Examples Smallest Vector Element Smallest Complex Element Smallest Element in Each Matrix Column Smallest Element in Each Matrix Row Minimum of Array Page Smallest Element Including Missing Values Smallest Element Indices Return Linear Indices Smallest Element Comparison Input Arguments A — Input array scalar | vector | matrix | multidimensional array | table | timetable dim — Dimension to operate along positive integer scalar vecdim — Vector of dimensions vector of positive integers missingflag — Missing value condition "omitmissing" (default) | "omitnan" | "omitnat" | "omitundefined" | "includemissing" | "includenan" | "includenat" | "includeundefined" B — Additional input array scalar | vector | matrix | multidimensional array | table | timetable method — Comparison method "auto" (default) | "real" | "abs" Output Arguments M — Minimum values scalar | vector | matrix | multidimensional array | table I — Index scalar | vector | matrix | multidimensional array | table C — Minimum elements from A or B scalar | vector | matrix | multidimensional array | table | timetable Extended Capabilities Tall Arrays Calculate with arrays that have more rows than fit in memory. C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™. GPU Code Generation Generate CUDA® code for NVIDIA® GPUs using GPU Coder™. HDL Code Generation Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™. Thread-Based Environment Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool. GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™. Distributed Arrays Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™. Version History R2024b: Specifying second input array as character array is not supported R2023b: Specifying second input array as character array will not be supported R2023a: Specify missing value condition R2023a: Perform calculations directly on tables and timetables R2021b: Specify comparison method R2018b: Operate on multiple dimensions See Also Functions Topics MATLAB Command Americas Europe Asia Pacific References

Minimum elements of array

collapse all in page

Syntax

M = min(A)

M = min(A,[],"all")

M = min(A,[],dim)

M = min(A,[],vecdim)

M = min(A,[],___,missingflag)

[M,I] =min(___)

[M,I] =min(A,[],___,"linear")

C = min(A,B)

C = min(A,B,missingflag)

___ = min(___,"ComparisonMethod",method)

Description

M = min(A) returns the minimum elements of an array.

  • If A is a vector, then min(A) returns the minimum of A.

  • If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A.

  • If A is a multidimensional array, then min(A) operates along the first dimension of A whose size does not equal 1, treating the elements as vectors. The size of M in this dimension becomes 1, while the sizes of all other dimensions remain the same as in A. If A is an empty array whose first dimension has zero length, then M is an empty array with the same size as A.

  • If A is a table or timetable, then min(A) returns a one-row table containing the minimum of each variable. (since R2023a)

example

M = min(A,[],"all") returns the minimum over all elements of A.

example

M = min(A,[],dim) returns the minimum element along dimension dim. For example, if A is a matrix, then min(A,[],2) returns a column vector containing the minimum value of each row.

example

M = min(A,[],vecdim) returns the minimum over the dimensions specified in the vector vecdim. For example, if A is a matrix, then min(A,[],[1 2]) returns the minimum over all elements in A because every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

example

M = min(A,[],___,missingflag) specifies whether to omit or include missing values in A for any of the previous syntaxes. For example, min(A,[],"includemissing") includes all missing values when computing the minimum. By default, min omits missing values.

example

[M,I] =min(___) also returns the index into the operating dimension that corresponds to the first occurrence of the minimum value of A.

example

[M,I] =min(A,[],___,"linear") also returns the linear index into A that corresponds to the minimum value in A.

example

C = min(A,B) returns an array with the smallest elements taken from A or B.

example

C = min(A,B,missingflag) also specifies how to treat missing values.

___ = min(___,"ComparisonMethod",method) optionally specifies how to compare elements for any of the previous syntaxes. For example, for a vector A = [-1 2 -9], the syntax min(A,[],"ComparisonMethod","abs") compares the elements of A according to their absolute values and returns a minimum value of -1.

Examples

collapse all

Smallest Vector Element

Open Live Script

Create a vector and compute its smallest element.

A = [23 42 37 15 52];M = min(A)
M = 15

Smallest Complex Element

Open Live Script

Create a complex vector and compute its smallest element, that is, the element with the smallest magnitude.

A = [-2+2i 4+i -1-3i];min(A)
ans = -2.0000 + 2.0000i

Smallest Element in Each Matrix Column

Create a matrix and compute the smallest element in each column.

A = [2 8 4; 7 3 9]
A = 2×3 2 8 4 7 3 9
M = min(A)
M = 1×3 2 3 4

Smallest Element in Each Matrix Row

Open Live Script

Create a matrix and compute the smallest element in each row.

A = [1.7 1.2 1.5; 1.3 1.6 1.99]
A = 2×3 1.7000 1.2000 1.5000 1.3000 1.6000 1.9900
M = min(A,[],2)
M = 2×1 1.2000 1.3000

Minimum of Array Page

Open Live Script

Create a 3-D array and compute the minimum over each page of data (rows and columns).

A(:,:,1) = [2 4; -2 1];A(:,:,2) = [9 13; -5 7];A(:,:,3) = [4 4; 8 -3];M1 = min(A,[],[1 2])
M1 = M1(:,:,1) = -2M1(:,:,2) = -5M1(:,:,3) = -3

To compute the minimum over all dimensions of an array, you can either specify each dimension in the vector dimension argument or use the "all" option.

M2 = min(A,[],[1 2 3])
M2 = -5
Mall = min(A,[],"all")
Mall = -5

Smallest Element Including Missing Values

Open Live Script

Create a matrix containing NaN values.

A = [1.77 -0.005 3.98 -2.95; NaN 0.34 NaN 0.19]
A = 2×4 1.7700 -0.0050 3.9800 -2.9500 NaN 0.3400 NaN 0.1900

Compute the minimum value of the matrix, including missing values. For matrix columns that contain any NaN value, the minimum is NaN.

M = min(A,[],"includemissing")
M = 1×4 NaN -0.0050 NaN -2.9500

Smallest Element Indices

Open Live Script

Create a matrix A and compute the smallest elements in each column as well as the row indices of A in which they appear.

A = [1 9 -2; 8 4 -5]
A = 2×3 1 9 -2 8 4 -5
[M,I] = min(A)
M = 1×3 1 4 -5
I = 1×3 1 2 2

Return Linear Indices

Open Live Script

Create a matrix A and return the minimum value of each row in the matrix M. Use the "linear" option to also return the linear indices I such that M = A(I).

A = [1 2 3; 4 5 6]
A = 2×3 1 2 3 4 5 6
[M,I] = min(A,[],2,"linear")
M = 2×1 1 4
I = 2×1 1 2
minvals = A(I)
minvals = 2×1 1 4

Smallest Element Comparison

Open Live Script

Create a matrix and return the smallest value between each of its elements compared to a scalar.

A = [1 7 3; 6 2 9]
A = 2×3 1 7 3 6 2 9
B = 5;C = min(A,B)
C = 2×3 1 5 3 5 2 5

Input Arguments

collapse all

AInput array
scalar | vector | matrix | multidimensional array | table | timetable

Input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable.

  • If A is complex, then min(A) returnsthe complex number with the smallest magnitude. If magnitudes areequal, then min(A) returns the value with the smallestmagnitude and the smallest phase angle.

  • If A is a scalar, then min(A) returns A.

  • If A is a 0-by-0 empty array, then min(A) isas well.

If A has type categorical, then it must be ordinal.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | categorical | datetime | duration | table | timetable
Complex Number Support: Yes

dimDimension to operate along
positive integer scalar

Dimension to operate along, specified as a positive integer scalar. If you do not specify the dimension, then the default is the first array dimension whose size does not equal 1.

Dimension dim indicates the dimension whoselength reduces to 1. The size(M,dim) is 1,while the sizes of all other dimensions remain the same, unless size(A,dim) is 0.If size(A,dim) is 0, then min(A,dim) returnsan empty array with the same size as A.

Consider an m-by-n input matrix, A:

  • min(A,[],1) computes the minimum of the elements in each column of A and returns a 1-by-n row vector.

    min - Minimum elements of array (1)

  • min(A,[],2) computes the minimum of the elements in each row of A and returns an m-by-1 column vector.

    min - Minimum elements of array (2)

vecdimVector of dimensions
vector of positive integers

Vector of dimensions, specified as a vector of positive integers. Each element represents a dimension of the input array. The lengths of the output in the specified operating dimensions are 1, while the others remain the same.

Consider a 2-by-3-by-3 input array, A. Then min(A,[],[1 2]) returns a 1-by-1-by-3 array whose elements are the minimums computed over each page of A.

min - Minimum elements of array (3)

missingflagMissing value condition
"omitmissing" (default) | "omitnan" | "omitnat" | "omitundefined" | "includemissing" | "includenan" | "includenat" | "includeundefined"

Missing value condition, specified as one of the values in this table.

ValueInput Data TypeDescription
"omitmissing"All supported data typesIgnore missing values in the input arrays, and compute the minimum over fewer points. If all elements in the operating dimension are missing, then the corresponding element in M is missing.
"omitnan"double, single, duration
"omitnat"datetime
"omitundefined"categorical
"includemissing"All supported data types

Include missing values in the input arrays when computing the minimum. If any element in the operating dimension is missing, then the corresponding element in M is missing.

"includenan"double, single, duration
"includenat"datetime
"includeundefined"categorical

BAdditional input array
scalar | vector | matrix | multidimensional array | table | timetable

Additional input array, specified as a scalar, vector, matrix, multidimensional array, table, or timetable. Inputs A and B must either be the same size or have sizes that are compatible (for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For more information, see Compatible Array Sizes for Basic Operations.

  • If A and B are both arrays, then they must be the same data type unless one is a double. In that case, the data type of the other array can be single, duration, or any integer type.

  • If A and B are ordinal categorical arrays, they must have the same sets of categories with the same order.

  • If either A or B is a table or timetable, then the other input can be an array, table, or timetable.

If B has type categorical, then it must be ordinal.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | categorical | datetime | duration | table | timetable
Complex Number Support: Yes

methodComparison method
"auto" (default) | "real" | "abs"

Comparison method for numeric input, specified as one of these values:

  • "auto" — For a numeric input array A, compare elements by real(A) when A is real, and by abs(A) when A is complex.

  • "real" — For a numeric input array A, compare elements by real(A) when A is real or complex. If A has elements with equal real parts, then use imag(A) to break ties.

  • "abs" — For a numeric input array A, compare elements by abs(A) when A is real or complex. If A has elements with equal magnitude, then use angle(A) in the interval (-π,π] to break ties.

Output Arguments

collapse all

M — Minimum values
scalar | vector | matrix | multidimensional array | table

Minimum values, returned as a scalar, vector, matrix, multidimensional array or table. size(M,dim) is 1, while the sizes of all other dimensions match the size of the corresponding dimension in A, unless size(A,dim) is 0. If size(A,dim) is 0, then M is an empty array with the same size as A.

I — Index
scalar | vector | matrix | multidimensional array | table

Index, returned as a scalar, vector, matrix, multidimensional array, or table. I is the same size as the first output.

When "linear" is not specified, I is the index into the operating dimension. When "linear" is specified, I contains the linear indices of A corresponding to the minimum values.

If the smallest element occurs more than once, then I contains the index to the first occurrence of the value.

C — Minimum elements from A or B
scalar | vector | matrix | multidimensional array | table | timetable

Minimum elements from A or B, returned as a scalar, vector, matrix, multidimensional array, table, or timetable. The size of C is determined by implicit expansion of the dimensions of A and B. For more information, see Compatible Array Sizes for Basic Operations.

The data type of C depends on the data typesof A and B:

  • If A and B arethe same data type, then C matches the data typeof A and B.

  • If either A or B is single,then C is single.

  • If either A or B isan integer data type with the other a scalar double,then C assumes the integer data type.

  • If either A or B is a table or timetable, then C is a table or timetable.

Extended Capabilities

The min function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced before R2006a

expand all

Specifying a second input array as a character array returns an error. This change minimizes confusion with other arguments that can be specified as character vectors, such as the missing value condition. To maintain the previous functionality, you can convert the second input array to double, for example, min(A,double(B),"includenan").

Specifying a second input array as a character array gives a warning and will generate an error in a future release. This change minimizes confusion with other arguments that can be specified as character vectors, such as the missing value condition. To maintain the previous functionality, you can convert the second input array to double, for example, min(A,double(B),"includenan").

Omit or include all missing values in the input arrays when computing the minimum value by using the "omitmissing" or "includemissing" options. Previously, "omitnan", "includenan", "omitnat", "includenat", "omitundefined", and "includeundefined" specified a missing value condition that was specific to the data type of the input arrays.

The min function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.

Specify the real or absolute value method for determining the minimum value of the input by using the ComparisonMethod parameter.

Operate on multiple dimensions of the input arrays at a time. Specify a vector of operating dimensions, or specify the "all" option to operate on all array dimensions.

See Also

Functions

  • mink | bounds | max | mean | median | sort | islocalmin | clip

Topics

  • Array Indexing

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

min - Minimum elements of array (4)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

min - Minimum elements of array (2024)

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Manual Maggio

Last Updated:

Views: 6000

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.