필터 지우기
필터 지우기

Can someone explain why I am getting the error "Not enough input arguments (line 4)"?

조회 수: 56 (최근 30일)
function [f] = f(x,y)
%PROBLEM3a
f = 1/(3*x-2*y+1); %line 4
y(1) = 0;
x(1) = 0;
step_sizeh = .1;
n_steps = 1./(step_sizeh);
for i = 1:n_steps;
y(i+1) = y(i) + step_sizeh*f(x(i),y(i));
x(i+1) = x(i)+step_sizeh;
end
end
  댓글 수: 3
Torsten
Torsten 2023년 11월 25일
편집: Torsten 2023년 11월 25일
Did you supply numerical values for a, b, M, N, w_state and x_n before you tried to call the function "iirFilt" ? If not, the function does "not have enough input arguments" to perform any kind of computation.
Walter Roberson
Walter Roberson 2023년 11월 25일
편집: Walter Roberson 2023년 11월 25일
When you have a variable named as a parameter in the function definition (such as x_n in this case), then MATLAB will never search any other environment to try to find a value for the variable. If you execute iirFilt without passing anything in, then when the code needs to use a variable named as a parameter but no value has been passed in, then MATLAB will generate an error message. MATLAB will never go looking in the base workspace or in the calling function for x_n if x_n is named as a parameter in the function definition. This is true even in the case of nested functions with shared variables: if you do not pass something in then it is an error to try to use the variable.
Likewise, if you have a name as a parameter in a function definition, then MATLAB will never search for the name as a function. Any named parameter in a function definition is "locked in" to being a variable (not a function) in the body of the function. You can see in the below example that even though you clear the definition of sum as being a variable, it got locked in as being a variable anyhow.
If you click on the green Run button in the editor, then that is equivalent to executing the function without passing anything in to the function: MATLAB will not look for a variable named x_n anywhere to pass the value in: the Run button is the same as executing iirFilt() with no parameters.
test_it
Not enough input arguments.

Error in solution>test_it (line 4)
sum(1:3)
function test_it(sum)
clear sum
sum(1:3)
end

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2012년 7월 26일
The first possiblity that comes to mind is your using ‘f’ for both your functon name and the variable inside the function. I suggest for a start:
function [z] = f(x,y)
Then since you also seem to call ‘f(x,y)’ recursively in this line:
y(i+1) = y(i) + step_sizeh*f(x(i),y(i));
I suggest you use an anonymous function here:
%PROBLEM3a
fcn = @(x,y) 1/(3*x-2*y+1); %line 4
z = fcn(x,y);
and change the ‘y(i+1)’ line to:
y(i+1) = y(i) + step_sizeh*fcn(x(i),y(i));
I also suggest you not use ‘i’ or ‘j’ as loop index variables because MATLAB uses these for its imaginary operators.
  댓글 수: 2
Zuleyka
Zuleyka 2012년 7월 26일
Thanks for all your advice. If you hadn't written the actual, I'm not quite sure I would have understood all the points since I'm not very familiar with Matlab.
Like what is an anonymous function, and is fcn a command? Anyway, the code works and I learned some new things. Thanks!
Star Strider
Star Strider 2012년 7월 26일
Anonymous functions ( http://www.mathworks.com/help/techdoc/math/bsgprpq-3.html ) are definitely worth learning about! They can make MATLAB much easier. (I also suggest you look up and learn about ‘inline’ functions. They also have their uses.)
The variable I called ‘fcn’ is just that — there is nothing special about the name. Here, it becomes the anonymous function I assigned it to, but it could be anything and I could have named the function almost anything except for ‘f’ because it refers to your function, or other variable names you used, or a number of MATLAB reserved words and commands.
A very easy way to find out if a name is ‘safe’ or a reserved word is to right-click on it in the Editor. A Help window will appear (or change if it is already open) to give you informaton on the function if it exists, or to say it cannot find anything about that function if it is not a MATLAB function. This is also a shortcut way to find documentation on a function if you need it in a hurry. It is an extremely useful feature.
You will quickly become quite knowledgable in MATLAB. It is usually easy to find code problems because we have all made many of those same errors. Be sure to share your knowldege of MATLAB with others who are learning.
Thank you for accepting my answer.

댓글을 달려면 로그인하십시오.

추가 답변 (5개)

Diego Tasso
Diego Tasso 2012년 7월 26일
Your getting that error because your compiling a function that does not have x or y defined. Its a normal error that occurs when the function is compiled. Just try calling the function from the command window and make sure to input variables for x and y ( i.e. in command window type "f(2,4)"). Another error statement is going to pop up when you execute line 10. That's your real problem.Also think about using "ii" instead of "i" since "i" is an already defined variable in MATLAB and may give you problems. Change the function name. I believe its confusing if not erroneous to use the same name for your function and for your output variable.
  댓글 수: 2
Diego Tasso
Diego Tasso 2012년 7월 26일
편집: Diego Tasso 2012년 7월 26일
Sorry I forgot to tell you to get rid of your initial error statement move lines five and six above line four. As for what your trying to do, I am unsure of.
Zuleyka
Zuleyka 2012년 7월 26일
편집: Zuleyka 2012년 7월 26일
Thanks for all the details! I did't know that "i" was already defined since my professor usually uses it in examples not pertaining to imaginary numbers. I also took your advice on the file name.
Oh, I'm making a loop for forwards euler, since our professor doesn't want us to use ode45.

댓글을 달려면 로그인하십시오.


Yanai
Yanai 2012년 7월 26일
You use the same name for a variable and for a function ("f") When you write f = .... matlab thinks you're trying to call the function f(x,y)

muhammad irfan
muhammad irfan 2019년 2월 24일
편집: Stephen23 2019년 2월 24일
EDIT: copyright code removed.
when i will run this program i face the error like this
(Error using mipbackwarddiff (line 17)
Not enough input arguments.)
kindly someone help me to solve this
  댓글 수: 2
Stephen23
Stephen23 2019년 2월 24일
편집: Stephen23 2019년 2월 24일
@muhammad irfan: as the error message states, most likely you have not used enough input arguments. But as you have not shown us how you are calling this function, we can only guess.
When I searched for "Medical Image Processing Toolbox Omer Demirkaya, Musa Asyali, Prasanna Shaoo" most results appear to be about this book:

댓글을 달려면 로그인하십시오.


Toni Bodunrin
Toni Bodunrin 2020년 11월 7일
편집: DGM 2023년 3월 4일
Getting not enough input arugmetns for this code, PLEASE HELP
function Dn=calculateFourierCoefficients(sig,period,n)
syms t;
w0 = (2*pi)/period;
N = n;
x = sig; %what was given to us
ak = zeros(1,2*N+1); %intialize a row vector of 2N+1 zeros
%calculate the period and store in T
for k = -N:N
ak(1,1+k+N) = 1/period * int(x * exp(-1i*k*w0*t), t, 0, period); % ak is fourier coefficient
end
ak(1,1+k+N)
  댓글 수: 7
Toni Bodunrin
Toni Bodunrin 2020년 11월 7일
편집: Walter Roberson 2020년 11월 8일
ohhh okay i see
I changed it to this but I am still getting the not enough input arguments error. Thank you for your help and patience in theis matter
function Dn=calculateFourierCoefficients( sig,period,n)
syms t
Dn= 1/period * int(sig * exp(-1i*n*w0*t), t, -period, period)
end
Walter Roberson
Walter Roberson 2020년 11월 7일
x = @(t) cos((3*pi*t)/10) + 0.5*sin((pi*t)/10);
That is a function handle.
Dn=calculateFourierCoefficients(x ,w0, g);
You pass the function handle to the function.
Dn= 1/period * int(sig * exp(-1i*n*w0*t), t, -period, period)
You multiply the function handle by something, without invoking the function handle. That would normally be an error, but possibly it invokes the function with no arguments.

댓글을 달려면 로그인하십시오.


Min You
Min You 2021년 9월 23일
Help I am getting the error "Not enough input arguments
function [A, B, C, D, N, Q] = Modify_Arrays(m, n)
% Check whether m,n are even and greater than 4
if m<4 || n<4 || mod(m,2)~=0 || mod(n,2)~=0
error('m & n must be even numbers greater than or equal to 4!!')
end
% Array A
A = ones(m, n);
% Array B
B = A;
B([1,end], :) = 0;
B(2:end-1, [1, end]) = 0;
% Array C
C = A;
C([1,end], [1,end]) = 0;
% Array D
D = A(2:end-1, 2:end-1);
% Array N
N = A;
N(:, 1) = 1:m;
N(1,2:end) = 2:n;
% Array Q
Q = A;
r = m/2;
c = n/2;
Q(1:r, 1:c) = 0;
Q(r+1:end, c+1:end) = 0;
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 9월 23일
When you pressed the green Run button, where where you expecting MATLAB to look to find out which value it should use for m and n ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by