Problems accepting integer values with power and algebraic symbols using inputdlg
이전 댓글 표시
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?
Thank you
Kind Regards
Scuba


채택된 답변
추가 답변 (1개)
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")
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!