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

2 views (last 30 days)
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?

Accepted Answer

Thomas
Thomas on 28 Jun 2012
Edited: Thomas on 28 Jun 2012
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

More Answers (1)

Wayne King
Wayne King on 28 Jun 2012
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

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!