MATLAB: When I use ^ to square a value or a vector, it gives me Error: The input character is not valid in MATLAB statements or expressions. how I can fix this problem

characterMATLAB

=3ˆ2 ↑ Error: The expression to the left of the equals sign is not a valid target for an assignment.

Best Answer

Two issues. First, using the = with nothing on the left hand side will generate the error you are getting because there is nothing listed on the left hand side to take the assignment. Second, the ˆ character in your post is a special character, not the actual ^ operator. Fixing both of these errors:
>> =3ˆ2 % With both errors
??? =3ˆ2
|
Error: The expression to the left of the equals sign is not a valid target for an
assignment.
>> x=3ˆ2 % With the assignment error fixed, but ˆ is not the same as ^
??? x=3ˆ2
|
Error: The input character is not valid in MATLAB statements or expressions.
>> x=3^2 % With both errors fixed
x =
9
Related Question