Matlab

How to Find Max and Min Value in Large Data Set Matrix in MATLAB

When we deal with very large matrices and data sets, it becomes very difficult to identify the maximum and minimum value of that data set or matrix. Also when we create a matrix using built-in functions like rand() and magic(), we do not know the entries of that matrix, so we do not have an idea about the minimum and maximum values of that matrix. To resolve these issues, MATLAB facilitates us with an approach to finding the maximum and minimum values of large matrices and data sets.

This guide is helpful for MATLAB users who are unaware of the method to find maximum and minimum values of the large data set and matrix in MATLAB.

How to Find the Min and Max Values in the Large Data Set and Matrix in MATLAB?

Finding the maximum and minimum values in a large data set can be easily done using the max() and min() functions. However, we have to use them separately. The bounds() function in MATLAB is a more efficient way to find the minimum and maximum values of a large data set or matrix. It is the built-in function in MATLAB that takes the matrix as an input and returns the maximum and minimum values of large data sets or matrices in MATLAB.

Syntax

The bounds() function uses a simple syntax in MATLAB:

[minA,maxA] = bounds(A)
[minA,maxA] = bounds(A,"all")
[minA,maxA] = bounds(A,dim)

Here,

The function [minA,maxA] = bounds(A) yield to obtain the minimum value minA and maximum value maxA of the given matrix or array A. Where minA equals min(A) and maxA equals max(A).

The function [minA,maxA] = bounds(A,” all”) yields to identify the minimum value minA as well as maximum value maxA over all entries of the given matrix or array A.

The function [minA,maxA] = bounds(A, dim) yield to identify the minimum and maximum values of each row of the given array A along the dimension dim.

Examples

Follow the given examples to learn how to compute the maximum and minimum values of the given matrix or data set using the bounds() function.

Example 1: How to Find the Min and Max Values of a 1D array in MATLAB?

In this example, we compute the maximum and minimum values of the given 1D array of random numbers having size 1-by-1000 using the bounds() function.

vect = randn(1,1000);
[min_vect, max_vect] = bounds(vect)

Example 2: How to Find the Max and Min Values of a Large Matrix in MATLAB?

This MATLAB code uses the bounds() function to identify the minimum and maximum values of the given large matrix having a size of 1000-by-1000.

A = magic(1000);
[min_A, max_A] = bounds(A,"all")

Example 3: How to Find the Max and Min Values of a Large Array in MATLAB?

The given MATLAB code uses the bounds() function to compute the minimum and maximum values of the given array having a size of 2-by-10-by-2.

A = randn(2,10,2);
[min_A, max_A] = bounds(A,2)

Conclusion

Finding the minimum and maximum values of a large data set or matrix is a common problem faced by data analysts. This becomes easy by using MATLAB’s built-in bounds() function that computes the minimum and maximum values of the given array or matrix. This guide has provided the basics of using the bounds() function in MATLAB to find the minimum and maximum values in a large dataset. The examples provided here will allow you to quickly learn the use of the bounds() function in MATLAB.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.