Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Aaron
Aaron am 28 Jun. 2012
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?

Akzeptierte Antwort

Thomas
Thomas am 28 Jun. 2012
Bearbeitet: Thomas am 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

Weitere Antworten (1)

Wayne King
Wayne King am 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

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by