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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:34:30+00:00 2026-05-26T00:34:30+00:00

I need to declare a function that has 32 arguments, so it would be

  • 0

I need to declare a function that has 32 arguments, so it would be handy to put an unique argument: an array of 32 elements.
I don’t find the syntax to do that, I’ve tried everythinh like:
function x=myfunction(str(32)) (etc…)
But without success.

  • 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-05-26T00:34:31+00:00Added an answer on May 26, 2026 at 12:34 am

    Unlike other languages, MATLAB can accept matrices as a single argument; so you could just check that the input argument is a vector of length 32:

    function x = myfunction(arg)
        if length(arg) ~= 32
            error('Must supply 32 arguments!');
        end
    
        %# your code here
    end
    

    If it’s a variable number of arguments, check out varargin:

    function x = myfunction(varargin)
    

    But for 32 arguments, consider using an input structure:

    function x = myfunction(argStruct)
    
        if length(fieldnames(argStruct)) ~= 32
            error('not enough arguments!');
        end
    

    Supply arguments in the structure, then pass the structure:

    >> myArgs = struct();
    >> myArgs.arg1 = 5;
    >> myArgs.arg2 = 7;
    >> %#(etc)
    >> x = myfunction(myArgs);
    

    Then in the function, you could either call argStruct.arg1, etc, directly; or unpack it into 32 different variables inside the function. I would give the fields descriptive names so you don’t refer to them as arg1, etc inside your function. For that many input arguments, people using the function probably won’t remember the order in which your function requires them to pass inputs to. Doing it with a struct lets users pass in arguments without needing to think about what order those inputs are defined.

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

Sidebar

Related Questions

I need to declare an array of pointers to functions like so: extern void
I need to declare the query variable outside the switch statement that way I
I need to declare 3d array variable but can't. int[][][] ary = new int[5][2][];
Need a function that takes a character as a parameter and returns true if
I have an array of structs. The struct has two function pointers. Each element
What I would like to do is have a static factory function that you
I am trying to query a table that has dates in it. I would
I need to declare square matrices in C# WinForms with more than 20000 items
I think in this case there is no need to declare a public constructor
I need to access some members marked internal that are declared in a third

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.