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

  • Context: MATLAB 
  • Thread starter Thread starter supraja
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
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: