Hey Guys, Imagine u have a GUI which hold the variable x = 1:10 (doubble). Now I want to create an Editbox which allows the user to enter a calculation algorithm.
for example: x*3.
Is it possible to convert this string (x*3) into an actual calculation algorithm ?

댓글 수: 1

Stephen23
Stephen23 2014년 9월 16일
The answers below give some solutions, including using eval and str2func , but keep in mind these could be dangerous as this allows the user to run arbitrary code, including system calls via MATLAB.

댓글을 달려면 로그인하십시오.

 채택된 답변

추가 답변 (1개)

Adam
Adam 2014년 9월 16일

0 개 추천

You can also create a function handle if you want, something like:
s = 'x*3';
s = ['@(x)' s];
f = str2func(s);
f(x);

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2014년 9월 16일

댓글:

2014년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by