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

4.344 views (last 30 days)
Why do I get the following error messages :
ERROR: Too many output arguments.
Too many input arguments.
Not enough input arguments.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Nov 2021
Edited: MathWorks Support Team on 26 Nov 2021
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
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 at the command prompt. For example, the following code indicates that the minus function requires two input arguments.
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)
muhammad ilyas khattak khattak
Edited: muhammad ilyas khattak khattak on 20 Jan 2022
@Walter Roberson Walter 🙏🏻😊🤝😊 I hope and pray that you are well... I am seeing help/guidance here in using MATLAB optimization tool by professionals here.. I have almost similar problem that i am getting "Too many output arguments." error...Though my matalb code is very long therefore I do not expect anyone to scroll through or read entirely my matlab code... However, I need some guidance/suggestion in my current problem so that I can get further closer to an error-free attempt... Your guidance/help may put me on a correct direction/path towards an error-free attempt... Many thanks in advance once again...😊🤝😊 For sake of convenience , I will append my till-date-develped/updated matlab code here in plain text (you can copy/run), once mathwork allow me to upload ....I tried to attach but mathworks limitation of daily upload is not permitting me to upload... Thanks once again..🙏🏻😊🤝
K>> x = fmincon(fun, X0, A, b, Aeq, beq, lb, ub, ncon, options);
Error using AllinOne14January2022V1>FCVEC06January2022V2
Too many output arguments.
Error in AllinOne14January2022V1>@(x)FCVEC06January2022V2 (line 950)
fun = @(x)FCVEC06January2022V2;
Error in fmincon (line 571)
[initVals.f,initVals.g] = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.

Sign in to comment.

More Answers (11)

Limabean on 5 May 2017
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.
Chris Morris
Chris Morris on 11 Jul 2022
With dotnet I discovered the way to get "To many output arguements" is to not realise the generated code creates a function with
int noutargs
as the only argument. I have a function that takes a single integer and returns a single argument, so it was mis interepting the argument as number of output arguments. In those circumstances you need to call:
functionName(1,<argument valuer>);

Sign in to comment.

navin gopaul
navin gopaul on 27 Mar 2014
Edited: navin gopaul on 27 Mar 2014
maybe because you edited your function and increased the number of input arguments but didn't click save on the editor for that function , then while trying to call this function from your main function, you are getting this error.

kailai nathan
kailai nathan on 18 Jan 2017
Edited: Walter Roberson on 22 Mar 2017
hi, I am not getting my output of my ybus.m file into my loadflow_gs.m file
the error displayed is too many output arguments.
function [yb,ych]=ybus
pls help me solve this as quickly

Emma Birkett
Emma Birkett on 20 Jul 2017
Thanks for the guidance. I had the same error and realised I was trying to refer to the session twice. I was using:
but needed to use

shiva kongari
shiva kongari on 8 Nov 2017
Edited: Walter Roberson on 8 Nov 2017
[mserRegions, mserConnComp] = detectMSERFeatures(I,...
'RegionAreaRange',[200 8000],'ThresholdDelta',4);
is there any wrong in these two lines of code ?
i am trying to execute my code (extract text from image) but it shows error here itself..
can anyone please help me out?
  1 Comment
Walter Roberson
Walter Roberson on 8 Nov 2017
R2016a was the first version that supported returning the second output for that call.
When using an old release, you should be looking at the documentation for that release, not the current documentation.

Sign in to comment.

Faith Leonard
Faith Leonard on 9 Apr 2019
Can someone explain how to fix the "too many inputs" error, I have tried a few differnt things and nothing seems to do the trick.
Screen Shot 2019-04-09 at 9.21.47 AM.png
  1 Comment
Walter Roberson
Walter Roberson on 9 Apr 2019
box() is a call to turn plot boxes around an axes on or off.
It appears that you are expected to be working with a local box() function with completely different purpose, but that the expected box.m is not on your path.
I do not seem to find any common toolbox for MATLAB that provides a box() function, but I could be overlooking it as "box" is a quite common term that matches many pages. My suspicion is that the box() you are expecting was provided as part of an assignment.

Sign in to comment.

Yashaswa Aryan
Yashaswa Aryan on 10 Apr 2019
%% Analysis of the market - week of last year
for i=1:168:8592
market = nansum(regulation_prices2016(i:i+168,2));
if market/336<=0.4 %down regulation
else, if 0.4<market/336<=0.6 %equilibrium
else, 0.6<market/336; %up regulation
The Bold highlited line shows an error of "Too many output arguments".
Pls help
  1 Comment
Stephen23 on 10 Apr 2019
Edited: Stephen23 on 10 Apr 2019
MATLAB's inbuilt alpha has no output arguments:
If you expect alpha to refer to something else, then clearly it is not accesible (e.g. a function that is not on the MATLAB search path, a variable not defined in that workspace, etc.)
You appear to be using alpha as if it was an array, but I do not see it defined anywhere in your code.

Sign in to comment.

%% Extract Features
[feats1,validpts1] = extractFeatures(rgb2gray(I1),points1);
[feats2,validpts2] = extractFeatures(rgb2gray(I2),points2);
I am getting follwing error while executing above 2 statements :
Error using extractFeatures
Too many output arguments.
  1 Comment
Walter Roberson
Walter Roberson on 5 Dec 2019
What do you see for
which -all extractFeatures
I suspect that you might have a third party toolbox installed that is interfering.

Sign in to comment.

SHUOFENG ZHOU on 12 May 2020
[audioIn,fs] = audioread("mht_a.wav");
noise = pinknoise(size(audioIn),'like',audioIn);
noisePower = sum(noise.^2,1)/size(noise,1);
signalPower = sum(audioIn.^2,1)/size(audioIn,1);
snr = 10*log10(signalPower./noisePower)
noisePowerdB = 10*log10(noisePower)
signalPowerdB = 10*log10(signalPower)
desiredSNR = 20;
scaleFactor = sqrt(signalPower./(noisePower*(10^(desiredSNR/10))));
noise1 = noise.*scaleFactor;
y = noise1 + audioIn;
The Bold highlited line shows an error of "Too many input arguments".
Pls help
Walter Roberson
Walter Roberson on 13 May 2020
Okay, with the breakpoint still at line 111 of audiowrite, run the code, and when it stops, give the command
dbstep in
and see if it gets into the parseInputs function or if it complains as soon as it tries to invoke that function.
If it starts executing the parseInputs function, use dbstep repeatedly until the error message shows up.

Sign in to comment.

mohammad ebrahimy
mohammad ebrahimy on 20 Jan 2022
I found an additional way to get thes error
I used a variable name for input and output of that function
[c,b] = My_func(a,b)
  1 Comment
Walter Roberson
Walter Roberson on 20 Jan 2022
No, that in itself is valid.
A = 3; B = 5;
[C, B] = My_func(A, B)
C = 8
B = 6
function [c,b] = My_func(a,b)
c = a + b;
b = b + 1;

Sign in to comment.

Captain Karnage
Captain Karnage on 4 Nov 2022 at 21:05
Adding to the category of "another way to get this error" that I don't see already list:
If you have a class method, and you forget to include the object as your first argument (typically by calling the method with obj. before the method), you can get this error.
Also, you will not be able to validate the correct number of arguments with nargin('functionName') either, because it will report -1 for your class methods.


Find more on Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by