MATLAB Solving Matlab Error: "The Expression to Left of Equals Sign

  • Thread starter Thread starter supraja
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion centers around resolving an error message that states, "The expression to the left of the equals sign is not a valid target for an assignment." This error typically occurs when there is an incorrect assignment in the code. A user is attempting to define a complex expression for variable E, but the error arises from a misunderstanding of assignment versus comparison in conditional statements. For example, using a single equals sign (=) instead of a double equals sign (==) in an if statement leads to this error. The conversation highlights the importance of correctly defining variables and using appropriate syntax in programming to avoid such issues. Additionally, a user successfully runs the expression with dummy values for the variables r, D, and Z, demonstrating that the expression itself is valid when the variables are properly defined.
supraja
Messages
1
Reaction score
0
i have tried for an hour but have been constantly getting an error saying "The expression to the left of the equals sign is not a valid target for an assignment".what should i do?

i need the expression
E=[Z*(r-1/D)+exp(Z*(r-1/D))-1].*exp(-r.*Z).*1/(r-1/D).^2 ;


please reply asap
 
Physics news on Phys.org
How do you define the rest of the variables (r, D, Z)? You posted only one line of code but I think the rest is relevant, since for example if I use dummy numbers I don't get an error:

Code:
r=2;
D=2;
Z=2;
E=[Z*(r-1/D)+exp(Z*(r-1/D))-1].*exp(-r.*Z).*1/(r-1/D).^2

E =

    0.1798

This error comes about when you try to do something such as,

Code:
if i = 2
 if i = 2
      |
Error: The expression to the left of the equals sign is not a valid target for an assignment.

You were trying to see IF i was equal to 2, but instead you assigned a value of 2 to i. The correct syntax would be,

Code:
if i == 2
    %do stuff
end
 
Last edited:

Similar threads

Replies
2
Views
3K
Replies
4
Views
1K
Replies
6
Views
2K
Replies
10
Views
3K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
6
Views
4K
Replies
2
Views
1K
Back
Top