How can i collect number without using eval function ?
Show older comments
I try to use int2str and num2str which didnot compute the problem. However, it computed ans = 51 43 50 If I give 3+2, it should compute 5 and show the screen which one can be defined ? What is something? Like example:
Number=input('Enter Number please:','s')
result=something(Number)
4 Comments
Stephen23
on 2 May 2016
@ahmet ozdemir: can you please give exact input examples, and what you want the output to be. Do you want the user to be able to input any arbitrary equation and get the evaluated result, or do you want them to input numeric values?
ahmet ozdemir
on 2 May 2016
CS Researcher
on 2 May 2016
@ahmet ozdemir: Did you see my recent solution? It does what you are asking for.
ahmet ozdemir
on 2 May 2016
Accepted Answer
More Answers (2)
The safest and most versatile:
num = str2double(input('Please enter a number:','s'));
CS Researcher
on 2 May 2016
You mean something like this:
Number=input('Enter Number please:','s');
eval(['result = ' Number])
3 Comments
ahmet ozdemir
on 2 May 2016
Stephen23
on 2 May 2016
1) the title states clearly "without using eval function"
2) eval should be avoided for many reasons. In this case it could be a security risk because it executes arbitrary code from the end user.
CS Researcher
on 2 May 2016
Oh I am sorry. I misread the title.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!