Not Enough Input Arguments

조회 수: 1 (최근 30일)
Karina Lopez Zamora
Karina Lopez Zamora 2021년 3월 2일
댓글: Walter Roberson 2021년 3월 2일
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

답변 (1개)

Steven Lord
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
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
Walter Roberson 2021년 3월 2일
xin = randn()
xin = -1.6940
yin = randn()
yin = -0.3612
output = first(xin, yin)
output = 3.0003
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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by