Not Enough Input Arguments
1 次查看(过去 30 天)
显示 更早的评论
Anyone knows how I can fix a 'not enough input arguments' error? I have the code below, and it points to my if statement. Thanl you!
function C = first(x,y)
if (x >= 0 && y >= 0)
C = x + y;
elseif ((x >= 0) && (y < 0))
C = x + y.^2;
elseif ((x < 0) && (y >= 0))
C = x.^2 + y;
elseif ((x < 0) && (y < 0))
C = x.^2 + y.^2;
end
end
0 个评论
回答(1 个)
Steven Lord
2021-3-2
Your function can be called with at most two inputs, and since it uses both inputs on the line you called out it must be called with at least two inputs. So you need to call it with exactly two inputs.
2 个评论
Karina Lopez Zamora
2021-3-2
So function C(x,y) = first(x,y) or when I assigned C to the expressions above?
Sorry, I'm still learning MATLAB.
Walter Roberson
2021-3-2
xin = randn()
yin = randn()
output = first(xin, yin)
function C = first(x,y)
if (x >= 0 && y >= 0)
C = x + y;
elseif ((x >= 0) && (y < 0))
C = x + y.^2;
elseif ((x < 0) && (y >= 0))
C = x.^2 + y;
elseif ((x < 0) && (y < 0))
C = x.^2 + y.^2;
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!