Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Not Enough Input Arguments

Asked by TheLimpNinja

TheLimpNinja (view profile)

on 7 Nov 2012

Hi, I'm very new to MATLAB and am having some trouble. Loads of people have ha this 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.

Thanks.

1 Comment

Jonathan Epperl

Jonathan Epperl (view profile)

on 7 Nov 2012

You call a function with not enough input arguments, as an example

sin()

will give you that error, because sin needs an argument -- what number do you want to compute the sine of?

Maybe you should start by working through the "Getting Started" in the Matlab Help, won't take you long but make a lot of things clear.

TheLimpNinja

TheLimpNinja (view profile)

Tags

Products

No products are associated with this question.

5 Answers

Answer by Akiva Gordon

Akiva Gordon (view profile)

on 8 Nov 2012

This might clear it up a bit:

By default, pressing the "Run" button (green "Play" button) or F5 will enter the function or script name of the active Editor file in the Command Window and execute that line. In this case, it will enter

>> Mec134function

This is incorrect syntax for this function, as you have defined it to require two input arguments; thus, you will get the error message stating that you have not provided enough input arguments. The function should be called as follows (assuming "w" and "theta_deg" are defined)

>> Mec134function(w,theta_deg)

If you want the function to be called with this syntax when pressing the "Run" button, you should edit the Run Configuration by pressing the little down arrow right next to the "Run" button (in R2012b - not sure about other versions), and entering in the code that you want to execute.

0 Comments

Akiva Gordon

Akiva Gordon (view profile)

Answer by TheLimpNinja

TheLimpNinja (view profile)

on 7 Nov 2012
Edited by Walter Roberson

Walter Roberson (view profile)

on 7 Nov 2012

Thanks :-)

will have a look at the "getting started"

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

that seems to give this error for line 2 but I'm not sure why.

1 Comment

Jan Simon

Jan Simon (view profile)

on 30 Nov 2012

@TheLimpNinja: Please add all details, which describe the problem in the questions - you can edit it. The answers section is reserved for answers.

TheLimpNinja

TheLimpNinja (view profile)

Answer by TheLimpNinja

TheLimpNinja (view profile)

on 7 Nov 2012

sorry the function is

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

if that's clearer :-)

2 Comments

Jonathan Epperl

Jonathan Epperl (view profile)

on 7 Nov 2012

This function needs 2 input arguments, w and theta_deg. If you type into the command window

Mec134function(2*pi, 120)

you should not be getting an error. If you do, please post your whole command and the whole error message.

David Barry

David Barry (view profile)

on 7 Nov 2012

Jonathan is correct, please ignore the other answer below.

As a complete aside, MATLAB has commands deg2rad and rad2deg.

TheLimpNinja

TheLimpNinja (view profile)

Answer by John Paul Donlon

John Paul Donlon (view profile)

on 7 Nov 2012

I think you need to define each input variable in the function file before it is used.

function [r]=Mec134function(w,theta_deg)
t2=10000;
% Enter the value(s) of theta_deg here.
theta_rad=(theta_deg./180).*pi;
t1=55090./(10*sin(theta_rad));
rx=(t1.*cos(theta_rad))-t2;
% Enter the value(s) of w here.
ry=w-(t1.*sin(theta_rad));
r=((rx).^2+(ry).^2).^0.5;
end

1 Comment

Walter Roberson

Walter Roberson (view profile)

on 7 Nov 2012

David indicates that this is incorrect.

John Paul Donlon

John Paul Donlon (view profile)

Answer by Brian Batson

Brian Batson (view profile)

on 29 Nov 2012
Edited by Brian Batson

Brian Batson (view profile)

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.

2 Comments

Walter Roberson

Walter Roberson (view profile)

on 30 Nov 2012

How are you initiating the running of the code?

Image Analyst

Image Analyst (view profile)

on 30 Nov 2012

When you called Mec134function(), did you pass in two arguments, or did you even pass in any arguments at all? You didn't just write that code into Mec134function.m and click the green run button did you? Because it needs two arguments. Did you pass it two arguments? That's what it means when it says "Not enough input arguments" - that you didn't pass in enough input arguments.

Brian Batson

Brian Batson (view profile)

Contact us