I got the error of incorrect argument data type or missing argument in call to function 'gamma'.
2 views (last 30 days)
Show older comments
function z=dist(x,rd,gm)
arguments
x (1,:) {mustBeInteger}
rd (1,:) {mustBePositive}
gm (1,:) {mustBePositive}
z= (rd.^x)*gamma(gm)./gamma(gm+x).*(hypergeom(1+x,gm+x,-rd));
end
function a = rdist(n,rd,gm)
u=rand(1,n);
x=int16(n);
for i=1:n
a=dist(x(i),rd(i),gm(i));
while a(i)<u(i)
x(i)=x(i)+1;
a=a+dist(x(i),rd(i),gm(i));
end
end
2 Comments
Answers (1)
Steven Lord
on 23 Aug 2022
The gamma function in MATLAB requires its input to be a floating-point number, specifically the input must be "Data Types: single | double"
answer = gamma(5)
If you try to call it on with a value of an integer type as input, you'll receive an error. The result of adding a double and an integer is of the integer type, as you can see by looking at the information for the result variable in the output of whos below.
d = 5;
in = int8(1);
result = d + in;
whos d in result
Calling double on result and calling gamma on that converted value will work, but calling gamma on result itself will not.
gamma(double(result))
gamma(result) % Will error
How is this relevant to your function? x must be of an integer type, so gm+x must be of that same integer type, and you try computing gamma(gm+x) in your code.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!