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

  • Home
  • SEARCH
  • 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 8941819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:23:21+00:00 2026-06-15T11:23:21+00:00

Possible Duplicate: Default Arguments in Matlab I have a function with about 7 parameters

  • 0

Possible Duplicate:
Default Arguments in Matlab

I have a function with about 7 parameters to be passed. 3 of them are mandatory and the rest 4 are optional parameters. I want to pass only the first 3 and the last parameter. How do I do this?

Let us say that the function is:
function[…] = fun(a, b, c, d, e, f, g)

a, b, c – required inputs.

d, e, f, g – optional inputs.

I want to call fun and pass values for a, b, c and g.

In R, I can specify this in a very neat way like:
fun(a=1, b=4, c=5, g=0);

What is the equivalent syntax in matlab?

  • 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-15T11:23:22+00:00Added an answer on June 15, 2026 at 11:23 am

    Unfortunately, there is no way to do this. You have to explicitly pass empty values for the parameters you do not want to pass, and you need to check that condition in your function to see, if a parameter has been passed or not, and if it is empty or not. Something like this:

    function fun(a, b, c, d, e, f, g)
        if nargin<3
            error('too few parameters');
        end
        if nargin<4 || isempty(d)
            d = default_value;
        end
        % and so on...
    end
    
    % call
    fun(a, b, c, [], [], g);
    

    In the end it might be easier to collect the optional parameters into one structure and check its fields:

    function fun(a, b, c, opt)
        if nargin<3
            error('too few parameters');
        end
        if nargin>3
            if ~isfield(opt, 'd')
                opt.d = default_value;
            end
        end
    end
    
    % call
    opt.g = g;
    fun(a, b, c, opt);
    

    It is easier to call the function, and you do not have to specify empty parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: python - returning a default value I have a function in a
Possible Duplicate: virtual function default arguments behaviour class Human{ virtual void print(int height =72){
Possible Duplicate: Invoking methods with optional parameters through reflection Name of the constructor arguments
Possible Duplicate: Default textbox border-style and width I have some TextBox on my page
Possible Duplicate: Why C# implements methods as non-virtual by default? I'm speaking primarily about
Possible Duplicate: least astonishment in python: the mutable default argument I want to understand
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm very confused about
Possible Duplicate: Are arrays or lists passed by default by reference in c#? I
Possible Duplicate: Stop default hashtag behavior with jquery I have some jquery code on
Possible Duplicate: Override default php function Is there a way to detect that a

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.