Categories

# Matlab min

‘Min’ is function used in Matlab to find minimum or smallest value from database. This function can be applied on any type of dataset like integers, characters, floating numbers, etc. Along with type of dataset it can be applied on any dimensions of data such as arrays, vectors, two dimensional elements, three dimensional elements, etc. If values are missing in dataset then most of the times ‘NaN’ represents null values, there are two ways to apply min function on this type of datasets. First function is ‘omitnan’, which ignores Nan values and second function is ‘includenan’, which is used to include Nan values in dataset.

## Syntax:

• min ( Input variable name )

`min ( Input )`

• min ( input variable name , [ ] , dimensions )

`min ( Input , [ ] , 2 )`

• min ( input variable name , [ ] , ‘ includenan ’ )

`min ( Input , [ ] , ‘ includenan ’ )`

• min ( input variable name , [ ] , ’ omitnan ’ )

`min ( Input , [ ] , ‘ omitnan ’ )`

## How min function work in Matlab?

‘Min’ function gives smallest value from given input as output. It is simple process to find smallest value from integers and floating numbers, but it is difficult and complex to calculate minimum value from characters and strings. if we apply min function on characters or strings then it works on ascii values it calculates ascii values first and then find smallest number from ascii numbers.

## Examples:

Let us discuss examples of Matlab Min.

## Example 1:

First let us consider one simple array or vector [ 20, 41, 30, 23,12, 6, 10, 45, 34 ] , which is declared as Input. These are simple integers so output after applying min function is 6.

## Matlab Code:

``````clc ;
clear all ;
Input = [ 20, 41, 30, 23, 12, 6, 10, 45, 34 ] disp ( ' Minimum Element ' ) ;
min ( Input)``````

## Example 2:

Let us consider one example with character elements as input [ ‘ A ‘ , ‘ B ‘ , ‘ D ‘ , ‘ E ‘ ], which is declared as Input. In character and string database min function will find out ascii values first and then it will calculate smallest value .in this example ASCII values of A, B, D, E are 65, 66, 68, 69 respectively. Therefore smallest value is 65.

## Matlab Code:

``````clc ;
clear all ;
Input = [ ' A ' , ' B ' , ' D ' , ' E ' ] disp ( ' Minimum Element ' );
min ( Input )``````

## Example 3:

Let us consider one matrix as input with three rows and three columns [ 34, 32, 67 ; 34, 21, 20 ; 45, 78, 10 ] ,which is declared as Input. If input is multidimensional then min function will work on each column individually. Therefore output of this example is 34, 21 and 10 which is illustrated in example 3 ( a ). If we want output in a different way then we can give dimensions to min function. In same example let us apply dimension as 1 then output will be 34,21 and 10 that means if dimension is one then it will work on each column individually which is illustrated in example 3 ( b ). And by considering same input if we apply dimension as 2 then it will work on each row and it will give a result on each row so output will be 32, 20, and 10, which is illustrated in example 3( c ).

## Matlab Code (a)

``````clc ;
clear all ;
Input = [ 34, 32, 67 ; 34 , 21, 20 ; 45, 78, 10 ] disp ( ' Minimum Element ' ) ;
min ( Input )``````

## Matlab Code ( b)

``````clc ;
clear all ;
Input = [ 34, 32, 67 ; 34, 21, 20 ; 45, 78,10 ] disp ( ' Minimum Element ' ) ;
min ( Input,[ ] ,1 )``````

## Matlab Code ( c )

``````clc ;
clear all ;
Input = [ 34, 32, 67 ; 34, 21, 20 ; 45, 78, 10 ] disp ( ' Minimum Element ' ) ;
min ( Input,[ ] ,2 )``````

## Example 4

In this example, we will consider one value in database which is NaN. Nan represents null values in any type of database. If there are NaN values in database and we apply min function without any instruction then automatically it will ignore the NaN value, which is illustrated in example 4(a).there are two functions in min function. One is omitnan and second is includenan. ‘omitnan’ will ignore NaN values and ‘Includenan’ will consider NaN values.

## Matlab code 4 (a)

``````clc ;
clear all ;
Input = [ 4.5 , 6.5, 6.0, 3.4, 3.2, 1.4, 1.9, 1.2, 4.9, NaN ] disp ( ' Minimum Element ' ) ;
min ( Input )``````

## Matlab code 4(b) –

``````clc ;
clear all ;
Input = [ 4.5, 6.5, 6.0, 3.4, 3.2, 1.4, 1.9, 1.2, 4.9, NaN ] disp ( ' Minimum Element ' ) ;
min ( Input , [ ] , ' includenan ' )``````

## Matlab Code 4( c )

``````clc ;
clear all ;
Input = [ 4.5, 6.5, 6.0, 3 .4, 3.2, 1.4, 1.9, 1.2, 4.9, NaN ] disp('Minimum Element');
min ( Input, [ ], 'omitnan' )``````