Problems accepting integer values with power and algebraic symbols using inputdlg
3 views (last 30 days)
Hey guys, I'm trying to pass an integer values through to an inptdlg GUI. That said, this input may be a big number (using the power notation and multiplication sign) therefore, the input may consist of multiplication and power signs etc., that are (im assuming) defined as strings or char? The problem arises when trying to convert the input from the user denoted as double_ans back into an integer value, i recieve a NaN as shown below in image 2. Is there any work arounds to this problem where I don't have to seperate the integer value from strings/symbols/chars?
To re-emphasise, when inputing a value such as 123*10^4 how do i re-interpret that into matlab as 1230000 of course without typing it long ways, in other words i would like to accept integer and string/symbols/etc using inputdlg?
More Answers (1)
Steven Lord on 13 Mar 2023
The str2double function is a bit particular about the formats of text that it will convert to double. The format you've described doesn't satisfy it. On the other end of the spectrum is a plain call to str2num, but that can be subject to the "Bobby Tables" problem (aka arbitrary code execution.) Calling str2num with Evaluation="restricted" (assuming you're using release R2022a or later) may be sufficient for your needs.
s = '123*10^4'
n = str2num(s, Evaluation="restricted")