How can i collect number without using eval function ?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
CS Researcher
2016년 5월 2일
@ahmet ozdemir: Did you see my recent solution? It does what you are asking for.
채택된 답변
CS Researcher
2016년 5월 2일
편집: CS Researcher
2016년 5월 2일
You can try something like this:
in = input('Please enter a number:','s');
s = strsplit(in,'+');
result = sum(str2double(s));
댓글 수: 3
CS Researcher
2016년 5월 2일
편집: CS Researcher
2016년 5월 2일
If it works you should accept my solution. You can update it to work for any operation. I will give you the solution to a basic 2 input problem:
in = input('Please enter a number:','s');
s = strsplit(in,'-');
result = -1*diff(str2double(s));
This will however only work for a basic subtraction. You should take it forward and modify it according to your need.
추가 답변 (2개)
CS Researcher
2016년 5월 2일
You mean something like this:
Number=input('Enter Number please:','s');
eval(['result = ' Number])
댓글 수: 3
Stephen23
2016년 5월 2일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!