필터 지우기
필터 지우기

I keep getting a syntax error with my program???

조회 수: 1 (최근 30일)
Aaron
Aaron 2012년 6월 28일
I'm creating a program that identifies x and y coordinates in a Cartesian coordinate system.
x=input('Enter value for x: '); y=input('Enter value for y: '); if x=0 & y=0 disp('This point is located at the origin.') elseif x>0 & y=0 fprintf disp('This point is located on the x-axis.') elseif x=0 & y>0 disp('This point is located on the y-axis.') elseif x>0 & y>0 disp('This point is located in the first quadrant.') elseif x<0 & y>0 disp('This point is located in the second quadrant.') elseif x<0 & y<0 disp('This point is located in the third quadrant.') elseif x>0 & y<0 disp('This point is located in the fourth quadrant.') end
I keep getting a syntax error with the x=0? The error tells me that '=' might be invalid Matlab syntax.
What am I doing wrong?

채택된 답변

Thomas
Thomas 2012년 6월 28일
편집: Thomas 2012년 6월 28일
in the If statement you need to use '==' Your first if statement would be
if x==0 & y==0
disp('This point is located at the origin.')
Your entire code
x=input('Enter value for x: ');
y=input('Enter value for y: ');
if x==0 & y==0
disp('This point is located at the origin.')
elseif x>0 & y==0
disp('This point is located on the x-axis.')
elseif x==0 & y>0
disp('This point is located on the y-axis.')
elseif x>0 & y>0
disp('This point is located in the first quadrant.')
elseif x<0 & y>0
disp('This point is located in the second quadrant.')
elseif x<0 & y<0
disp('This point is located in the third quadrant.')
elseif x>0 & y<0
disp('This point is located in the fourth quadrant.')
end

추가 답변 (1개)

Wayne King
Wayne King 2012년 6월 28일
x=input('Enter value for x: ');
y=input('Enter value for y: ');
if x==0 & y==0 disp('This point is located at the origin.')
elseif x>0 & y==0 fprintf disp('This point is located on the x-axis.')
elseif x==0 & y>0 disp('This point is located on the y-axis.')
elseif x>0 & y>0 disp('This point is located in the first quadrant.')
elseif x<0 & y>0 disp('This point is located in the second quadrant.')
elseif x<0 & y<0 disp('This point is located in the third quadrant.')
elseif x>0 & y<0 disp('This point is located in the fourth quadrant.'); end

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by