Why do spaces between arithmetic operators cause errors when decimal numbers are involved in MATLAB 7.0.4 (R14SP2)?

1 view (last 30 days)
If I put spaces in between arithmetic or logical operators such as +,-,*,/, &,^ etc. with a leading decimal and no leading 0, it will yield an error, assuming that my variable is a function. For example:
A=2;
A * .5
Yields the error:
??? Error: "A" was previously used as a variable,
conflicting with its use here as the name of a function.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
As noted in the "Late Breaking News" section of the release notes for MATLAB 7.0.4 (R14SP2):
When MATLAB sees an identifier, followed by some whitespace, an apparent MATLAB operator, and some more whitespace, it attempts to decide whether it is looking at part of an expression or assignment, or a command. If the character following the second whitespace cannot legally follow a MATLAB operator, MATLAB treats the line as a command. In R14SP2, a bug was introduced that incorrectly listed dot as one of the characters that cannot follow an operator. This is correct if dot is used as an operator, but incorrect if dot is used in a context such as .5. Thus, if you say
A * .5
you will typically get a mystifying message saying that "A" was previously used as a variable. This will most likely be seen at the command line only, although it might happen rarely in scripts or functions. It should not affect assignment statements or function calls. There are two workarounds:
Remove all the spaces:
A*.5
Or, put a zero in front of the dot:
A * 0.5

More Answers (0)

Categories

Find more on Entering Commands in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!