Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

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

From: Tanvir Mudhar

Date: 19 Oct, 2010 19:05:07

Message: 1 of 4

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?

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

From: Sean

Date: 19 Oct, 2010 19:15:07

Message: 2 of 4

"Tanvir Mudhar" <tanvir.husky@gmail.com> wrote in message <i9kq53$chf$1@fred.mathworks.com>...
> 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?

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

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

From: Loren Shure

Date: 19 Oct, 2010 19:17:11

Message: 3 of 4


"Tanvir Mudhar" <tanvir.husky@gmail.com> wrote in message
news:i9kq53$chf$1@fred.mathworks.com...
> 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?

= 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://blogs.mathworks.com/loren/
http://matlabwiki.mathworks.com/MATLAB_FAQ

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

From: Matt J

Date: 19 Oct, 2010 19:19:03

Message: 4 of 4

"Tanvir Mudhar" <tanvir.husky@gmail.com> wrote in message <i9kq53$chf$1@fred.mathworks.com>...
>
> 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?
=========

For example, this

x<0 && y = 0;

should really be this

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us