Not enough input arguments for an anonymous function.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have this anonymous function:
g = @(x,k) exp(cos(x))^k
I am getting this error:
Not enough input arguments.
Error in solution>@(x,k)exp(cos(x))^k (line 5)
g = @(x,k) exp(cos(x))^k
Im not sure the fix for this because x and k are both represented in the function.
2 Kommentare
Voss
am 12 Feb. 2023
x and k are both represented in the function, yes, but how are you calling the function? If you call it with fewer than two arguments you'll get that error.
% defining g:
g = @(x,k) exp(cos(x))^k
% calling g with 2 arguments:
g(pi,2) % ok
% calling g with 1 argument:
g(pi) % error
You haven't shown how you are calling the function g, so check on that.
Antworten (1)
the cyclist
am 12 Feb. 2023
Bearbeitet: the cyclist
am 12 Feb. 2023
I think you probably wanted to raise to the power element-wise, so I changed your function to
g = @(x,k) exp(cos(x)).^k;
But that won't cause the error you got.
How are you calling it? This works:
g = @(x,k) exp(cos(x)).^k;
g(1:5,3)
0 Kommentare
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!