Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:54:09+00:00 2026-06-06T02:54:09+00:00

When I pass a function (let’s call it f ) into my Base function

  • 0

When I pass a function (let’s call it f) into my Base function , the Base function doesn’t recognize
the f function , without using '' quotes , here’s the code :

function y = test(a, b, n ,f)

if ( rem(n,2) ~= 0 )
   error ( 'n is not even' )
end

% create a vector of n+1 linearly spaced numbers from a to b
x = linspace ( a, b, n+1 );

for i = 1:n+1
    % store each result at index "i" in X vector
    X(i) = feval ( f, x(i) );
end
y=sum(X);
end

And this is f.m :

function [y] = f (x)
y = 6-6*x^5;

When I run from command line with quotes :

>> [y] = test(0,1,10,'f')

y =

   52.7505

but when I remove them :

>> [y] = test(0,1,10,f)
Error using f (line 2)
Not enough input arguments.

Where is my mistake ? why can’t I execute [y] = test(0,1,10,f) ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:54:11+00:00Added an answer on June 6, 2026 at 2:54 am

    The function feval expects either the function name (i.e., a string) or a function handle as input. In your code, f is neither a name, nor a handle. Use either the string 'f' or the handle @f when calling your base function test.

    If, as posted in the comments, function handles are not allowed per assignment in the call to the base function, you can still use the function handle to create a string with the name of the function. This functionality is provided by the function func2str:

    functionName = func2str(@f); 
    
    test(0,1,10,functionname);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using a linq query, how can i pass parameters into the groupby function? Depend
so im using a simple submit binding to pass a function data: <form data-bind=submit:
I'm trying to make simple script using jquery $post function to pass data to
How would I pass a list of values into a function, where the values
I understand how to pass an array to a function and let that function
Given a higher-order function like the following: let call (f : unit -> 'a)
I have the following code which turns a string, that I pass into the
I want to let my android app call a function written in javascript and
Let's say I have this : class whatever(object): def __init__(self): pass and this function:
Can you call a Javascript function that expects let's say five arguments, and supply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.