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 feval Matlab
 

feval Matlab

Priya Pedamkar
Article byPriya Pedamkar

Updated July 3, 2023

feval Matlab

 

 

Introduction to Feval in Matlab

MATLAB is a programming environment that is interactive and is used in scientific computing. It is extensively used in many technical fields where problem-solving, data analysis, algorithm development, and experimentation are required. The discipline-specific software is extensively written using MATLAB.
In this article, we will study how to use ‘feval’ function in MATLAB.

Watch our Demo Courses and Videos

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

Before we start learning how ‘feval’ function works in MATLAB, let us understand why we need it.

Feval Function:

Feval function is used to evaluate the function output of a function by using the arguments passed inside a single parenthesis input. It accepts the function name passed as a “string” as its first argument. Please keep in mind that MATLAB suggests the use of a ‘function handle’ for the purpose of reference invocation. Function handles have the advantage of reliability and additional performance and offer source file control.

Let us now understand the syntax of ‘Feval function’ in MATLAB:

Syntax:

[a1, a2, ..., aN] = feval (function, inp1, inp2, ..., inp M)

Description:

1. feval takes a function as its first argument, which is passed as a string (in quotes)
2. The name of the function is usually defined by M-file
3. feval (function, inp1, inp2, …, inp M) will evaluate the value of ‘function’ at the input arguments.
4. Function parameter here must be the name of a function; we cannot use path information.

Examples of feval Matlab

Let us now understand what the code for ‘feval function’ looks like in MATLAB, with the help of various examples.

Example #1

In this example, we will find the average of elements of an array using ‘feval function’ We will need to follow the following 2 steps:

1. Create an array whose average we need

2. Pass the function ‘mean’ as a string inside the function ‘feval’

Code:

A = [1 4 6 7 0 2]

[Defining the input array ‘A’] [Mathematically, the mean of A must be 3.3333]

feval (‘mean’, A)

[Passing the mean function as 1st argument and input array ‘A’ as 2nd argument]

Input:

A = [1 4 6 7 0 2] feval ('mean', A)

Output:

feval Matlab 1

As we can see, by passing ‘mean’ as an input argument to our ‘feval function’, we are able to get the mean of our input array.

Example #2

In this example, we will find the standard deviation of elements of an array using ‘feval function’ We will need to follow the following 2 steps:

1. Create an array whose standard deviation we need

2. Pass the function ‘std’ as a string inside the function ‘feval’

Code:

A = [2 4 9 15 0 2]

[Defining the input array ‘A’] [Mathematically, the standard deviation of A must be 5.6451]

feval (‘std’, A)

[Passing the std function as 1st argument and input array ‘A’ as 2nd argument]

Input:

A = [2 4 9 15 0 2] feval ('std', A)

Output:

feval Matlab 2

As we can see, by passing ‘std’ as an input argument to our ‘feval function,’ we are able to get the standard deviation of our input array.

Example #3

In this example, we will find the value of the sine function at a particular point. We will need to follow the following 2 steps:

1. Pass the ‘sin’ as a string inside the function ‘feval’

2. Pass the point at which we need to get the value as 2nd argument

Code:

A = -pi/2

[Defining the point at which we need value of sine function] [Mathematically, the value of sin is -1 at -pi/2]

feval (‘sin’, A)

[Passing the sin function as 1st argument and the point -pi/2 as 2nd argument]

Input:

A = -pi/2
feval ('sin', A)

Output:

feval Matlab 3

As we can see, by passing ‘sin’ as input argument to our ‘feval function,’ we are able to get its value at -pi/2.

Example #4

We will combine two input strings using the ‘strcat’ function in this example. We will need to follow the following 2 steps:

1. Pass the two input strings inside the function ‘feval’

2. Pass the function ‘strcat’ to concatenate the 2 strings

Code:

a = feval ('strcat', 'learn', ' feval')

[‘strcat’ is passed as 1st argument] [Passing the strings ‘learn’ and ‘feval’ as 2nd and 3rd argument, respectively]

Input:

a = feval ('strcat', 'learn', ' feval')

Output:

Example 4

Conclusion

‘feval function’ can be used in MATLAB to pass both the function and its arguments inside one parenthesis. Please remember that in its latest versions, MATLAB recommends function handle as a better option than using feval.

Recommended Articles

This is a guide to feval Matlab. Here we discuss the introduction, syntax, Description, and examples with code implementation, respectively. You may also have a look at the following articles to learn more –

  1. MATLAB Toolbox
  2. MATLAB Colon
  3. Matlab Integral
  4. Matlab gca

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
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

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?

🚀 Limited Time Offer! - 🎁 ENROLL NOW