Converting string to function/number
6 views (last 30 days)
Show older comments
Hello, sorry to bother your time. So in this case, my problem is, i'm trying to design an app using app designer that can take user input in string and convert it into numbers. However, when i try to use some mathematical function like 'sin, cos, exp' etc, as an input, i want those strings to be converted into the mathematical function as they were stated. How can i achieve this?
Answers (3)
Rik
on 26 May 2022
The way to avoid eval in this case is to use str2func:
f=str2func('cos');
f(pi)
0 Comments
Walter Roberson
on 27 May 2022
str2sym()
matlabFunction is commonly used together with str2sym()
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!