The min() function in MATLAB returns the smallest value among the elements of the array or matrix. The min() function of MATLAB also returns the index of the smallest number of the provided data set. This function accepts the various input arguments including scalar, multidimensional array, vector, and matrix. The min() function quickly and conveniently determines the minimum value among the given data set.
Syntax
The format for using the min() function in MATLAB is given below:
dim value |
Purpose |
1 | Determine the smallest value from each column of the matrix |
2 | It is used to find the minimum value of the row |
In the below sample code, we are finding the minimum value of the row of the 5×5 matrix:
r = min(data, [ ], 2)
3: MATLAB min() Function to Get the Index of the Minimum Value of a Matrix
If you want to find the minimum value from an array with an index, you can use the following syntax:
Consider the following sample code to find the index of the element with the smallest value. The r will return the smallest value of each column of the matrix, and i will return the index position of the smallest element:
[r, i] = min(data)
4: MATLAB min() Function with “all” Parameter
If you want to identify the smallest value from the matrix, you can use the all parameter. The syntax of using the all parameter with the min() function is as follows:
Consider the following example to find the minimum value from 5×5 elements.
r = min(data, [], 'all')
Bottom Line
The min() function in MATLAB is an essential tool for finding the minimum value within an array or a matrix. It can quickly find the smallest value from an array or matrix, making it valuable for data analysis, modeling, and simulation tasks. By utilizing the min() function, MATLAB users can easily extract critical information from their data.