6,582 views (last 30 days)

Show older comments

Hi, I'm very new to MATLAB and I am having some trouble. Lots of people have had the same problem but nobody seems to be able to explain or solve it in plain English. Could somebody please explain what this error is and how to fix it?

I have a simple function:

function [r]=Mec134function(w,theta_deg)

t2=10000;

theta_rad=(theta_deg./180).*pi;

t1=55090./(10*sin(theta_rad));

rx=(t1.*cos(theta_rad))-t2;

ry=w-(t1.*sin(theta_rad));

r=((rx).^2+(ry).^2).^0.5;

end

It seems to give this error for line 3 but I'm not sure why.

Thanks.

Akiva Gordon
on 8 Nov 2012

Edited: MathWorks Support Team
on 27 Nov 2018

Your function defines 2 input arguments (w and theta_deg). When you run Mec134function, you must specify exactly two inputs, otherwise you will get the error "Not enough input arguments".

For example, if you run the Mec134function in the command window without specifying any arguments:

>> Mec134function

You get this error:

Not enough input arguments.

Error in Mec134function (line 3)

theta_rad=(theta_deg./180).*pi;

If you run the Mec134function and specify two input arguments, "w" and "theta_deg" (assuming "w" and "theta_deg" are defined), you do not get the error message:

>> Mec134function(w,theta_deg)

If you have the file "Mec134function.m" open in the Editor and you try to run the function by pressing the "Run" button or F5, MATLAB runs the Mec134function without any input arguments, and you get the error "Not enough input arguments". The "Run" button dropdown menu then opens prompting you to enter values for the missing input arguments.

Add the desired values and press enter. The values you enter are set as the default inputs when you click the "Run" button or F5 in the future.

To change the values, press the down arrow below the "Run" button and enter new values.

TheLimpNinja
on 7 Nov 2012

Edited: Walter Roberson
on 15 Jul 2016

Steven Lord
on 27 Dec 2016

Prior to release R2015b the deg2rad and rad2deg functions were part of Mapping Toolbox. In that release they moved into MATLAB.

As another solution that avoids converting between degrees and radians, MATLAB also has functions sind and cosd for computing the sine and cosine of angles in degrees and those have been part of MATLAB for quite some time. [I don't remember exactly when they were introduced.]

TheLimpNinja
on 7 Nov 2012

Edited: Walter Roberson
on 7 Nov 2012

Waldemiro Kubucama
on 1 Aug 2020

Brian Batson
on 29 Nov 2012

Edited: Brian Batson
on 29 Nov 2012

I too am very new to Matlab, and tried to run the code above in .m (JP Donlon on Nov. 7th). However, I keep getting an error stating "Not enough input arguments." I'm not sure what this means, because I have attempted to run other code by professors which works on other computers. Is it something with my preference settings?

Also, when I run the Code Analyzer, there are no issues...not sure what is going on.

Walter Roberson
on 29 Mar 2020

https://www.mathworks.com/matlabcentral/answers/53100-not-enough-input-arguments#comment_109973

Annie micheal
on 15 Jul 2016

Edited: Walter Roberson
on 15 Jul 2016

How to rectify this error

Error using DetectFace (line 68)

Not enough input arguments.

the code is given below

I=imread('lena.jpg');

minFace = 20; % minimal size of the face that you are searching for

maxFace = 4000; % maximal size of the face that you are searching for

overlappingThreshold = 0.5; % overlapping threshold for grouping nearby detections

numThreads = 24; % number of cpu threads for parallel computing

if nargin > 2 && ~isempty(options)

if isfield(options, 'minFace') && ~isempty(options.minFace)

minFace = options.minFace;

end

if isfield(options, 'maxFace') && ~isempty(options.maxFace)

maxFace = options.maxFace;

end

if isfield(options, 'overlappingThreshold') && ~isempty(options.overlappingThreshold)

overlappingThreshold = options.overlappingThreshold;

end

if isfield(options, 'numThreads') && ~isempty(options.numThreads)

numThreads = options.numThreads;

end

end

%%test detector

if ~ismatrix(I)

I = rgb2gray(I);

end

candi_rects = NPDScan(model, I, minFace, maxFace, numThreads);

%%post processing

if isempty(candi_rects)

rects = [];

return;

end

Walter Roberson
on 15 Jul 2016

Why did you use nargin and return when you wrote this script ? nargin is defined as being 0 within scripts and return can lead to odd behavior when used within a script .

When I search around, it looks to me as if this code is ripped off from https://github.com/biotrump/NPD/blob/master/NPDFaceDetector/DetectFace.m which is a function not a script . An example of calling that function is given in the comments there:

I = imread('lena.jpg');

load('model.mat');

rects = DetectFace(npdModel, I);

You cannot just remove the function line from a function and assign to one variable and expect it to work.

REEMA MOHANTY
on 27 Dec 2016

Edited: Walter Roberson
on 26 May 2017

clc; clear; close all;

xo=0.4;

A=[];

b=[];

Aeq=[];

beq=[];

Q=100;

R=1;

N = 50;

U0= zeros(100,1);

% Umin= -1*ones(100,1);

% Umax=1*ones(100,1);

% U = fmincon(@cost1,U0,A,b,Aeq,beq,Umin,Umax,[],[],N);

x=xo; h = 0.1;

xo=[-0.5,0.5];

options = optimoptions(@fmincon,'Algorithm','sqp');

U = fmincon(@cost1,U0,[],[],[],[],[],[],@confuneq,options);

for k =1:N

S1= F(x(k),U(k));

S2=F(x(k)+0.5*h*S1,U(k));

S3=F(x(k)+0.5*h*S2,U(k));

S4=F(x(k)+h*S3,U(k));

x(k+1) = x(k) + (1/6)* (S1+ 2*S2+ 2*S3 + S4)*h;

k = k + 1 ;

end

% plot(x);

plot(U);

grid on

figure(); plot(x)

grid on

I new to matlab.Can anyone help me to fix the iisue here.

Its showing not enough input arguments.

vani shree
on 3 Mar 2017

Edited: Walter Roberson
on 3 Mar 2017

Hello sir,I am newer to matlab. I am getting error in this code like "preprocessing requries more input arugument to run". can you please to run this program. my project topic is recognition and matching fake logos using filters.

function img=preprocessing(I)

[x y o]=size(I);

if o==3

I=rgb2gray(I);

end

I=im2double(I);

%%MEDIAN FILTER

med=medfilt2(I);

figure,imshow(med)

title('MEDIAN FILTERED IMAGE')

[psnr_med,mse_med]=psnr(I,med)

%%AVERAGE FILTER

out7= imfilter(I, fspecial('average'));

figure,imshow(out7)

title('MEAN FILTERED IMAGE')

[psnr_avg,mse_avg]=psnr(I,out7)

%%GAUSSIAN FILTER

gau=imfilter(I,fspecial('gaussian'));

figure,imshow(gau)

title('GAUSSIAN FILTER IMAGE')

[psnr_gau,mse_avg]=psnr(I,gau)

%%WEINER FILTER

psf=fspecial('gaussian',7,10);

image1=imfilter(I,psf,'conv','circular');

var1=(1/256)^2/12;

var2=var(I(:));

wei=deconvwnr(image1,psf,(var1/var2));

figure,imshow(wei);title('WEINER FILTERED IMAGE');

[psnr_wei,mse_wei]=psnr(I,wei)

psnr_all=[psnr_med,psnr_avg,psnr_gau,psnr_wei];

psnr_max=max(psnr_all);

val=find(psnr_all==psnr_max);

if val==1

img=med;

disp('median have high psnr');

elseif val==2

img=out7;

disp('mean have high psnr');

elseif val==3

img=gau;

disp('gaussian have high psnr');

else

img=wei;

disp('weiner have high psnr');

end

Steven Lord
on 24 Mar 2017

Ganesh Petkar
on 18 Apr 2017

I am getting error for below function as "Not enough input arguments. "

delayed_signal = mtapped_delay_fcn(input);

Walter Roberson
on 18 Apr 2017

Wendell
on 26 May 2017

Edited: Walter Roberson
on 26 May 2017

Hi I'm trying to run Dr. John Stockie's matlab code but I am getting a "Not enough input argument" error. I'm not very well verse with Matlab, so I would appreciate any help...Thank you. I am pasting the code:

function C = ermak( x, y, z, H, Q, U, Wset, Wdep )

% ERMAK: Compute contaminant concentration (kg/m^3) using the

% Gaussian plume model, modified for a deposition and settling

% velocity. This code handles a single source (located at the

% origin) and multiple receptors.

%

% Input parameters:

%

% x - receptor locations: distance along the wind direction, with

% the source at x=0 (m)

% y - receptor locations: cross-wind direction (m)

% z - receptor locations: vertical height (m)

% H - source height (m)

% Q - contaminant emission rate (kg/s)

% U - wind velocity (m/s)

% Wset - gravitational settling velocity (m/s)

% Wdep - deposition velocity (m/s)

%

% Output:

%

% C - contaminant concentration (kg/m^3)

%

% References: Ermak (1977), Winges (1990/1992).

% First, define the cut-off velocity, below which concentration = 0.

Umin = 0.0;

% Determine the sigma coefficients based on stability class C --

% slightly unstable (3-5 m/s).

ay = 0.34; by = 0.82; az = 0.275; bz = 0.82;

sigmay = ay*abs(x).^by .* (x > 0);

sigmaz = az*abs(x).^bz .* (x > 0);

% Calculate the eddy diffusivity (m^2/s).

Kz = 0.5*az*bz*U*abs(x).^(bz-1) .* (x > 0); % K = 0.5*U*d(sigma^2)/dx

% Calculate the contaminant concentration (kg/m^3) using Ermak's formula.

if U < Umin,

C = 0 * z;

else

Wo = Wdep - 0.5*Wset;

C = Q ./ (2*pi*U*sigmay.*sigmaz) .* exp( -0.5*y.^2./sigmay.^2 ) .* ...

exp( -0.5*Wset*(z-H)./Kz - Wset^2*sigmaz.^2/8./Kz.^2 ) .* ...

( exp( -0.5*(z-H).^2./sigmaz.^2 ) + ...

exp( -0.5*(z+H).^2./sigmaz.^2 ) - sqrt(2*pi)*Wo*sigmaz./Kz .* ...

exp( Wo*(z+H)./Kz + 0.5*Wo^2*sigmaz.^2./Kz.^2 ) .* ...

erfc( Wo*sigmaz/sqrt(2)./Kz + (z+H)./sqrt(2)./sigmaz ) );

ii = find(isnan(C) | isinf(C));

C(ii) = 0; % Set all NaN and inf values to zero.

end

and the error message refers to "sigmay" in line 31

aarthy reddy R
on 4 Sep 2019

Edited: Walter Roberson
on 14 Oct 2019

function test(num1, num2,small,s)

load (small, num1, num2)

s = sum(num1, num2)

end

this the code for this i'm getting these errors

Not enough input arguments.

Error in test (line 3)

load (small, num1, num2)

Walter Roberson
on 14 Oct 2019

Note: if you pass in the name of a variable as the fourth parameter, then the function you posted will not set that variable to the result of the sum. If you want to return a value in MATLAB you need to code it on the left side of an "=" in the function line. For example,

function s = test(num1, num2, small)

load (small, num1, num2)

s = sum(num1, num2)

end

This is unlikely to work the way you want it. In order for the load() to work there, small and num1 and num2 would each have to be a character vector or else a scalar string variable, and num1 and num2 would have to be in the same form as valid MATLAB variable names. Those names would have to be found inside the .mat file named by the small variable.

With the form of load() you have used, MATLAB would normally "poof" the variable names into existence. However, when you use end matching a function statement, you make a promise to MATLAB that you will not poof variables into existence, and MATLAB is permitted to give an error or to ignore the magically created variables. Therefore after the load, num1 and num2 are probably going to continue to be the character vectors or string objects, and you would attempt to call sum() passing those in. sum() would give an error if the first parameter, num1 is a string object, but would be okay with num1 being a character vector. There are a limited number of character vectors or scalar string objects that are valid for the second parameter of sum(), namely 'all', 'double', 'native', 'default', 'includenan', or 'omitnan' . It would be surprising if you happened to name your variables any of those...

Chapat
on 11 Mar 2020

Edited: Walter Roberson
on 11 Mar 2020

Hello. Am new in Matlab and I want to do my assignment with this function refraction_2layers and Matlab is saying error using refraction_2layers (line 18 and 25) Here is the whole program

function refraction_2layers(v1, v2, z, FIRST_ARRIVALS_ONLY);

% refraction_2layers(v1, v2, z);

%

% Creates travel time plots for a two-layers system with layer velocities

% v1 and v2 and layer 1 thickness of z

% The FIRST_ARRIVALS_ONLY FLAG may be set to 1 to plot only the first arrivals. By

% default, all arrivals are plotted.

if nargin < 4 FIRST_ARRIVALS_ONLY = 0; end

%% X-positions for geophones (m, relative to source)

x = [0:5:300];

%% Direct wave %% Travels along ground surface (at velocity v1)

t1 = x./v1;

%% Head wave

%% Refracts along z1-z2 boundary

%% Travel time depends on velocities of both layers

%% and thickness of layer 1 only (thickness of layer 2 irrelevant)

t2 = (2*z*sqrt(v2^2-v1^2)/(v1*v2))+x./v2; %% Note slope should be 1/v2!

xcrit = 2*z*v1/(sqrt(v2^2-v1^2));

if isreal(xcrit)

a = min(find(x>xcrit));

end

crossover = ((2*z*sqrt(v2^2-v1^2))/(v1*v2))/(1/v1-1/v2);

b = max(find(x<= crossover));

if FIRST_ARRIVALS_ONLY

plot(x(1:b),t1(1:b)*1000, '.--')

hold on

if isreal(t2)

plot(x(b:end), t2(b:end)*1000, 'r.--')

end

else

plot(x,t1*1000, '.--')

hold on

if isreal(t2)

plot(x(a:end), t2(a:end)*1000, 'r.--')

end

end

xlabel('GEOPHONE OFFSET (m)')

ylabel('TIME (ms)')

grid on

legend('DIRECT WAVE', 'HEAD WAVE')

title(['z1 = ', num2str(z), ' m; v1 = ', num2str(v1), ' m/s; v2 = ', num2str(v2), ' m/s'])

axis ([0 300 0 300])

hold off

Walter Roberson
on 11 Mar 2020

I formatted your code for you to make it readable to other people, but I suspect that I did not exactly preserve the line boundaries, so we do not know which lines are giving you the problem. Please mark them by using comments. Please also give the exact error messages.

Also please check the position of the end statements. It looked to me as if you might have had two extra end statements.

Josilyn Dostal
on 23 Apr 2020

I am really struggling to figure out this "not enough input arguments" error in my code. Any help would be greatly appreciated! This is for a batch distillation problem, and the error is referring to the temp function near the bottom. The code and error are below:

P = 912; % mmHg or 1.2 atm

L0 = 100; % Moles liquid in the still initially

A = [6.90565 6.95464]; B=[1211.033 1344.8]; C=[220.79 219.482]; % Antoine Constants

% x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%

% xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%

xtspan = linspace(0.40,0.80,100);

[xt, L] = ode45(@Moles, xtspan, L0);

L = L(end);

fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);

% Vapor liquid equilibrium ratio, K

function Kt = EquilibriumRatio(Psatt)

Kt = Psatt/P;

end

% Toluene vapor pressure

function Psatt = VaporPressuret(T,A,B,C)

Psatt = 10^(A(2)-B(2)/(T+C(2)));

end

% Benzene vapor pressure

function Psatb = VaporPressureb(T,A,B,C)

Psatb = 10^(A(1)-B(1)/(T+C(1)));

end

% ODE

function dLdx = Moles(xt,L)

T0 = 95.585;

%options = odeset('RelTol',1e-6,'AbsTol',1e-8);

%options = optimset('PlotFcns',{@optimplotx,@optimplotfval});

%options = optimset('Display','iter'); % show iterations

options = optimset('Display','off','TolX',1e-6); % Options

T = fzero(@temp, T0, options);

Psatt = VaporPressuret(T);

Kt = EquilibriumRatio(Psatt);

dLdx = L/(xt*(Kt-1));

end

function Tempfun = temp(T,xt,P,A,B,C)

Psatt = VaporPressuret(T,A,B,C);

Psatb = VaporPressureb(T,A,B,C);

Tempfun = Psatt*xt + Psatb*(1-xt) - P;

end

>> project2

Error using fzero (line 306)

FZERO cannot continue because user-supplied function_handle ==> temp failed with the error below.

Not enough input arguments.

Error in project2>Moles (line 30)

T = fzero(@temp, T0, options);

Error in odearguments (line 90)

f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 115)

odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Error in project2 (line 7)

[xt, L] = ode45(@Moles, xtspan, L0);

Maria hassan
on 13 Jul 2020

Hi,

I am getting error 'Not enough input arguments.' I am trying online trail oversion. When I click run icon, it does not allow me to enter the value for the input as there is no option for entering the values. Any advice here please?

Best

Sarah

Gurwinder pal singh Bhinder
on 27 Nov 2020

hi

I am new to matlab. i am getting error message "extract_features" requires more input arguments to run.

anderror in command window :

>> Extract_Features

Not enough input arguments.

Error in Extract_Features (line 2)

img1 = imread(filename);

code is written below:

function Extract_Features(filename,flag)

img1 = imread(filename);

if ndims(img1) == 3; img1 = rgb2gray(img1); end % Color Images

disp(['Extracting features from ' filename ' ...']);

fir=ext_finger(img1,0);

fir=fir(fir(:,3)<5,:);

if flag ==1

figure;

imshow(img1);

hold on

fir1=find(fir(:,3)==1);

fir3=find(fir(:,3)==3);

plot(fir(fir1,1),fir(fir1,2),'r+');

plot(fir(fir3,1),fir(fir3,2),'bo');

end

filename2=filename; filename2(end-1)='x'; filename2(end)='t';

save(filename2,'fir','-ascii');

end

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

Start Hunting!