I am receiving a "Parse error at '=' ..." whenever trying to assign a value to a variable

I was editing a script that worked fine until at certain point I tried to assign a new value to a variable and received a "Parse error at '=' ..." whenever trying to assign a value to an arg:
nstr = 0.89 % MPa nominal stress
the ewual sign underlined red for error and a mouse pointer hovered over it the error message would pop up:
"Parse error at '=' usage ight be invalid in MATLAB syntax:
When I attempted running the script the error message in command window would be:
Error: File: ImportEMData_021.m Line: 40 Column: 8
Unsupported use of the '=' operator. To compare values for equality, use '=='. To specify name-value
arguments, check that name is a valid identifier with no surrounding quotes.
This is the first instance of nstr in the script.
I have checked to confirm that nstr is not used as a function call in Matlab 2024a (negative) then, just on case changed the variable name (found/replaced all isntances to
nomStr = 0.89 % MPa
Then tried in some other part of the script
A =
and as soon as the equal sign would be added the error pops up...
Please advise
Lech

Answers (1)

There is likely something incorrect somewhere in the preceding code, e.g.:
ohno = [... <- missing closing bracket.
... more code
nstr = 0.89 % MPa nominal stress
Unsupported use of the '=' operator. To compare values for equality, use '=='. To specify name-value arguments, check that name is a valid identifier with no surrounding quotes.
Either:
  • debug this yourself
  • if you want us to help debug it for you then please show us the complete code e.g. by uploading the script by clicking the paperclip button oy by posting the code in a comment.

2 Comments

Bingo!
Thank you so much. I should have thought of it, but it is getting late.
Happened when I uncommented a long unused line, which missed a closing bracket.
All back to normal now!
One thing that can help identify this type of problem is to Smart Indent the code. Once you've done that, look for places where a line doesn't start in the column that you expected it to start, but started in a different column (usually further right.)

Sign in to comment.

Asked:

on 15 Apr 2024

Commented:

on 15 Apr 2024

Community Treasure Hunt

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

Start Hunting!