min and max functions in matlab

Matlab has built-in functions for finding the minimum and maximum values of an array or a list of values.

min function

The min function finds the minimum value of an array or vector. Syntax:

main.m
min(A)
7 chars
2 lines

where A is the array or vector.

Example:

main.m
A = [5, 3, 8, 1, 9];
min(A)
28 chars
3 lines

Output: 1

max function

The max function finds the maximum value of an array or vector. Syntax:

main.m
max(A)
7 chars
2 lines

where A is the array or vector.

Example:

main.m
A = [5, 3, 8, 1, 9];
max(A)
28 chars
3 lines

Output: 9

These functions can also be used with multiple input arguments to find the minimum or maximum value in comparison to the values of the rest of the inputs.

related categories

gistlibby LogSnag