Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Aaron
Aaron el 28 de Jun. de 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?

Respuesta aceptada

Thomas
Thomas el 28 de Jun. de 2012
Editada: Thomas el 28 de Jun. de 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

Más respuestas (1)

Wayne King
Wayne King el 28 de Jun. de 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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by