MATLAB: Not Enough Input Arguments

errorinput

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.

Best Answer

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.