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 8866803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:52:47+00:00 2026-06-14T16:52:47+00:00

I create a function function y = getValue(modelName, param, option) open_system(modelName); runModel(option); y =

  • 0

I create a function

function y = getValue(modelName, param, option)
    open_system(modelName);
    runModel(option);
    y = getActiveFun(param);
end

I would like when calling this function to have the choice to pass or not argument option
from some other files I call the function with all arguments and sometimes I would like to call it without passing option argument ?

I would like to call : getValue(modelName, param) from other files

How could I do that ?

  • 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-14T16:52:47+00:00Added an answer on June 14, 2026 at 4:52 pm

    The simplest way to do this is to use the nargin variable:

    function y = getValue(modelName,param,option)
        open_system(modelName);
    
        if (nargin < 3)
            # No option passed, do something like
            runModel('defaultOption')
        else
            # Option passed
            runModel(option);
        end
        y = getActiveFun(param);
    end
    

    nargin is just the number of input arguments that were actually submitted. Thus, nargin == 3 indicates that the option parameter has been set, nargin < 3 that it has not been set.

    Thus, you could now always call your function like

    result = getValue('myModel', myParameter)
    

    or with all parameters

    result = getValue('myModel', myParameter, someOption)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this procedure in the database: CREATE OR REPLACE FUNCTION replacePageRelevance(id INT, value
I would like to create a function where I can pass in an arbitrary
I can create function pointers in Fortran 90, with code like real, external ::
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
It is common and easy to create function like: var f = function(){ alert(something);
Like the parameter in ISNULL function? Something we can use to define: create function
I have the following function trying to create a callback InstanceContext from metadata of
This function loops all properties of an object to create the updatequery to save
I would like to create a stack with array of int (2 dimensional :

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.