Why do I get the error message "Too Many Input/Output Arguments" when I try to execute a function?

조회 수: 1,348 (최근 30일)
Why do I get the following error messages:
Too many output arguments. Too many input arguments. Not enough input arguments.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 10월 8일
편집: MathWorks Support Team 2024년 10월 8일
Explanation:
A function you are trying to call expects fewer input/output arguments, or more input/output arguments, than you have provided to it.
Common causes:
  1. You have passed a function more input arguments than it expected to receive, perhaps by passing a list of inputs rather than a vector of inputs, or have tried to obtain two outputs from a function that only returns one.
  2. You have multiple functions with the same name. One possible way this can happen is when you create a function with the same name as a built-in MATLAB function. To identify which version of the function MATLAB is calling, use the which function as follows:
    which -all <function-name> % replace <function-name> with the name of the function you are calling
    This will show you all instances of the function that MATLAB can access. If you find a custom function, rename or remove it to avoid conflicts with MATLAB's built-in functions.
Solution:
Verify that you have specified the correct number of input and/or output arguments. If necessary, use the 'which' function to determine which version of the function MATLAB is calling.
To determine the number of input and output arguments in a function definition, use 'nargin' and 'nargout' with the function name in the MATLAB Command Window. For example, the following code indicates that the 'minus' function requires two input arguments.
nargin('minus')
If you are writing a new function and you see these errors, make sure that the function declaration contains sufficient arguments.
Example demonstrating this error:
TooManyArguments.m (attached)
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 5월 21일
The error occurs when you have an assignment statement in which there are more output variables than the number of outputs that the call can provide. For example if you had
[x, y] = atan2(theta)
then that would be a problem because atan2() can only return one output.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Limabean
Limabean 2017년 5월 5일
I found an additional way to get the the error "too many input arguments"
I had a class defined in an @folder, with functions in their own files. The primary class definition contains a signature for the function. I had declared 2 arguments in the function, but the signature for the function in the main file still had just one argument.
Solution: make sure the arguments listed in the function signature in your class file matches the arguments in the function you defined in the separate file.
This same thing holds true for "too many output arguments" as well; make sure the function signature matches.

카테고리

Help CenterFile Exchange에서 Functions에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by