How do I evaluate a function within a string such as 'sin(x)' for given x values?
Show older comments
I am making a program which allows for user input of different functions. I made a dialog box with inputdlg, but the result was a string and I cant figure out how to evaluate the given function numerically.
This is the input part of the code so far. What am I doing wrong?
func=inputdlg('Input Function: y=') func1=str2num(func)
I have also tried using eval()
func=inputdlg('Input Function: y=') func1=eval(func)
My goal is that when someone inputs sin(x), the result is func='sin(x)' and func1 is sin(x) evaluated for the x-values.
Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Data Types 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!