Can someone explain why I am getting the error "Not enough input arguments (line 4)"?
104 ビュー (過去 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 件のコメント
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
function test_it(sum)
clear sum
sum(1:3)
end
採用された回答
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 件のコメント
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
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
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.
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)
0 件のコメント
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
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
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
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
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
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
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 Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!