EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab max
 

Matlab max

Updated March 8, 2023

Matlab max

 

 

Introduction to Matlab max

In Matlab ‘max’ function is used to find or calculate the maximum element from a given database. It compares all the values in integers and returns the maximum value. Max function supports single dimensional datasets as well as multidimensional datasets. It also performs on all data – types like integers, floating numbers, characters, complex numbers, and strings. If the dataset is having null values, then there are different methods to consider such values. It has various options like ‘omitnan’, ’includenan’, dim’, ’nanflag’, etc.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax

  • max( Input variable name )

min ( Input )

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

max ( Input , [   ] , 1 ) , max ( input , [  ] , 2 )

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

max ( Input , [  ] , ‘ includenan ’ )

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

min ( Input , [  ] , ‘ omitnan ’ )

How does max function work in Matlab?

Max function performs on series of elements, if the dataset is one dimensional in the form of vectors or array, then it is simple to calculate maximum elements, but if the dataset is multidimensional and large elements are present in the dataset, then it is a complicated process. This function calculates the maximum value individually on each row and each column. The maximum of characters and strings is calculated based on the ASCII value of all elements.

Examples

Here are the following examples mention below

Example #1

Let us consider one array of integer elements 76, 65, 45, 78, 43, 32, which is declared as input. All the elements are integers; therefore max function will give 78 as output, which is illustrated in example 1(a).In example 1(b) ,input data is in form of characters like ‘A’,’V’,’M’,’R’,’C’,’D’,’F’. min function will find out ascii values first, and then it will calculate the maximum value. Therefore the smallest value maximum value is 86. And if the dataset is an array of strings, the string is an array of characters; therefore in strings, also max function performs like characters only. In example 1(c ), input is ‘HELLO’, ‘HI’, ‘BYE’, ‘GOOD’. This function will consider the first letter of each letter, and by comparing all the first letters, we will get 89 as output which is the ascii value of character ‘Y’.

Matlab code for Example 1(a):

clc ;
clear all;
input = [76, 65, 45, 78 , 43, 32] disp ('Output ')
max (input)

Output:

Matlab max output 1

Matlab code for Example 1(b):

clc ;
clear all ;
input = [ 'A', 'V', 'M', 'R', 'C', 'D', 'F' ] disp ('Output ')
max (input)

Output:

Matlab max output 2

Matlab code for Example 1(c ):

clc ;
clear all ;
input = [ 'HELLO', 'HI', 'BYE', 'GOOD' ] disp ('Output ')
max (input)

Output:

Matlab max output 3

Example #2

Let us consider one example with a multidimensional database. In example 2(a), input has three columns and four rows; if we apply the max function on input, we will get three values as output. These three values are the maximum elements of each column. We can also instruct the dimensionality of the matrix. If we want maximum values concerning columns, then the ‘1’ dimension is used, which is illustrated in Example 2(b), and if we want maximum value concerning rows, then the ‘2’ dimension is used, which is illustrated in example 2(c).

Matlab code for Example 2 ( a ):

clc;
clear all;
input = [45 ,34, 87 ; 65, 54, 34 ; 67, 68, 65 ; 65, 67, 5 2 ] disp ('Output ')
max (input)

Output:

output 4

Matlab code for Example 2 (b):

clc;
clear all;
input = [45 , 34, 87 ; 65, 54, 34 ; 67, 68, 65 ; 65, 67, 52 ] disp ('Output ')
max (input, [ ] , 1 )

Output:

output 5

Matlab code for Example 2(c):

clc;
clear all;
input = [45 ,34, 87 ; 65, 54, 34 ; 67, 68, 65 ; 65, 67, 52 ] disp ('Output ')
max ( input, [ ] , 2)

Output:

output 6

Example #3

If some values are missing or some values are Null in a database, then there is one way to perform on such databases. Nan represents null values. If there are NaN values in the database and we apply the min function without any instruction, then automatically, it will ignore the NaN values. There are two ways in max function. One is omitnan, and the second is includenan. ‘Omitnan’ will ignore NaN values, and ‘Includenan’ will consider NaN values. In example 3(a), ‘omitnan’ is used; this will ignore all Nan values and compare other values. And in example 3(b), includenan function is used, which will include the presence of Nan value and directly give output as Nan by considering Nan is the maximum element.

Matlab code for Example 3(a):

clc ;
clear all ;
input = [4, 6, 34, 21, 1, 2, NaN, NaN, 45, 3 4, NaN] disp ('Output ')
max (input, [ ], 'omitnan')

Output:

output 7

Matlab code for Example 3(b):

clc ;
clear all ;
input = [4, 6, 34, 21, 1, 2, NaN, NaN, 45, 34, NaN] disp ('Output ')
max (input, [ ], 'includenan')

Output:

output 8

Conclusion

In this article, we have seen the ‘max’ function. This function compares all elements from the database and finds the maximum value from the database. There is no limitation of dimensionality of the dataset to use this operation. Along with all types of datasets, it also works on all data – types like integers, floating numbers, complex numbers, characters, and strings.

Recommended Articles

This is a guide to Matlab max. Here we discuss How does max function works in Matlab and examples along with the codes and outputs. You may also look at the following articles to learn more –

  1. Matlab gca
  2. Matlab Double Integral
  3. Signal Processing Matlab
  4. Matlab fplot()

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW