Why does calling STR2NUM('figure') open a figure window?

1 view (last 30 days)
I type the following code in the MATLAB command prompt:
str2num('figure')
This will cause a figure to open; however, it should only return and empty matrix '[]'. This behavior does not occur when performing the following code:
str2double ('figure')

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
STR2NUM does the conversion by calling the EVAL function on the string. In the documentation for STR2NUM, the following paragraph addresses the issue:
"CAUTION: STR2NUM uses EVAL to convert the input argument, so side
effects can occur if the string contains calls to functions. Use
STR2DOUBLE to avoid such side effects or when S contains a single
number."
Using STR2DOUBLE will return a "NaN" value.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!