The expression to the left of the equals sign is not a valid target for an assignment.

The expression to the left of the equals sign is not a valid target for an assignment.

Post by Tanvir Mud » Thu, 21 Oct 2010 04:05:07


My code is:
(starts with a if statment):
.....
elseif x<0 && y = 0;
d=pi;
disp(d)
elseif x=0 & y>0;
d= pi/2;
disp(d)
elseif x=0 & y<0;
d=-pi/2;
disp(d)
elseif x= 0 & y=0;
d=0;
disp(d)
end

the issue? It keeps underlining the equal signs in the code and tells me "The expression to the left of the equals sign is not a valid target for an assignment."
can someone tell me whats wrong with it?
 
 
 

The expression to the left of the equals sign is not a valid target for an assignment.

Post by Sean » Thu, 21 Oct 2010 04:15:07


A single '=' is an assignment as in a = 0, you just set a to equal 0. '==' is a test, is a equal to 0?

 
 
 

The expression to the left of the equals sign is not a valid target for an assignment.

Post by Loren Shur » Thu, 21 Oct 2010 04:17:11


= is the assignment operator. To test for equality, use ==
You might want to read the Getting Started with MATLAB documentation. In
your case, you may also want to switch your & operators with && assuming x
and y are always scalar values.

--
Loren
http://www.yqcomputer.com/
http://www.yqcomputer.com/
 
 
 

The expression to the left of the equals sign is not a valid target for an assignment.

Post by Matt » Thu, 21 Oct 2010 04:19:03


=========

For example, this

x<0 && y = 0;

should really be this

x<0 && y == 0; %Note the '=='