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)
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.
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:
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.
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 on 8 Nov 2017
Edited: Walter Roberson on 8 Nov 2017
[mserRegions, mserConnComp] = detectMSERFeatures(I,...
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?
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.
Yashaswa Aryan on 10 Apr 2019
%% Analysis of the market - week of last year
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".
SHASHANK LOKHANDE on 5 Dec 2019
%% 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.
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".
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)
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.