EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • All Courses
    • All Specializations
  • Blog
  • Enterprise
  • Free Courses
  • All Courses
  • All Specializations
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Calling Functions in Matlab
 

Calling Functions in Matlab

Updated March 13, 2023

Calling Functions in Matlab

 

 

Introduction to Calling Functions in Matlab

Calling a function, also referred to as invoking a function, is used to pass the control of the program to the required function, which in turn performs defined tasks and returns the control of the program back to the main program if the return statement of this function is executed or if the function-ending brace is encountered. A function is called by simply passing the required arguments or parameters into the name of the function. In this topic, we are going to learn about Calling Functions in Matlab.

Watch our Demo Courses and Videos

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

Below is the table showing some of the functions provided by MATLAB:

Function Details
1.       Remainder Used to find the remainder of a division
2.       Integral Used to integrate a function or symbolic expression
3.       Diff Used to differentiate a function or symbolic expression
4.       Max Used to find the maximum value
5.       Mean Used to find average or mean

Examples of Calling Functions in Matlab

Let us now understand the syntax to call the above functions in MATLAB:

Example #1

In this example, we will learn how to call the ‘remainder function’ in MATLAB.

Syntax:

A = rem(x, y)

Below are the steps to be followed:

  1. Initialize ‘Dividend’ and ‘Divisor’
  2. Pass the ‘Dividend’ and ‘Divisor’ as parameters to the rem function

Code:

x = 29

[Initializing the Dividend]

y = 5

[Initializing the Divisor]

A = rem(x, y)

[Passing the above variables to the rem function] [We are calling or invoking the function ‘rem’ bypassing the variables declared as input parameters to it]

Input:

x = 29
y = 5
A = rem(x, y)

Output:

Calling Functions in Matlab output 1

As we can see in the output, we have obtained the remainder of the input variables by calling the rem function.

Example #2

In this example, we will learn how to call ‘integral function’ in MATLAB.

Syntax:

A = integral(fx, min, max)

Below are the steps to be followed:

  1. Create the function to be integrated. for this example, we will take fx = x^4 * exp(-x) * cos(x) as our input function
  2. Pass the function along with the limits of integration as the parameters to the integral function

Code:

fx = @(x)x.^4.*exp(-x).*cos(x);

[Creating the function ‘fx’ in MATLAB]

A = integral(fx, 0, Inf)

[Passing the above function to the integral function. Here we have also passed the limits of integrations] [We are calling or invoking ‘integral’ bypassing the function to be integrated and limits of integration as parameters]

Input:

fx = @(x)x.^4.*exp(-x).*cos(x);
A = integral(fx, 0, Inf)

Output:

Calling Functions in Matlab output 2

As we can see in the output, we have obtained the integral of the input function by calling the integral function.

Example #3

In this example, we will learn how to call the ‘max function’ in MATLAB.

Syntax:

A = max(Z)

Below are the steps to be followed:

  1. Initialize the array whose maximum value we need
  2. Pass the array as a parameter to the max function

Code:

Z = [2 5 8 1 10];

[Initializing the array]

A = max(Z)

[Passing the array to the max function] [We are calling or invoking ‘max’ bypassing the array whose maximum value we need as a parameter]

Input:

Z = [2 5 8 1 10];
A = max(Z)

Output:

output 3

As we can see in the output, we have obtained the maximum number out of all the numbers present in the array by calling the max function.

Example #4

In this example, we will learn how to call ‘mean function’ in MATLAB.

Syntax:

A = mean(Z)

Below are the steps to be followed:

  1. Initialize the array whose mean value we need
  2. Pass the array as a parameter to the max function

Code:

Z = [2 0 8 11 10];

[Initializing the array]

A = mean(Z)

[Passing the array to the mean function] [We are calling or invoking ‘mean’ bypassing the array whose mean value we need as a parameter]

Input:

Z = [2 0 8 11 10];
A = mean(Z)

Output:

output 4

As we can see in the output, we have obtained the mean of the numbers present in the array by calling the mean function.

Conclusion

  1. ‘Calling a function’ passes the control of the program to the function
  2. A function is called by passing the parameters or arguments into the name of the function
  3. Once a function performs its defined tasks, the control of the program is passed back to the main program.

Recommended Articles

This is a guide to Calling Functions in Matlab. Here we discuss the Examples of Calling Functions in Matlab along with the codes, inputs, and outputs. You may also have a look at the following articles to learn more –

  1. Simplify Matlab
  2. Ceil Matlab
  3. Matlab loglog()
  4. Heaviside MATLAB
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

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

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 Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW