0

Some Matlab functions handle string functions representation as f='a^x^b+sin(c*x)+d' --i.e. Curve Fitting, Optimization, etc.--

Suppose the variables a,b,c,d and x are given. Is there any function for evaluating f from its string representation?

Brethlosze
  • 1,452
  • 17
  • 36

1 Answers1

1

You can do eval(f), but using eval is really discouraged https://uk.mathworks.com/help/matlab/matlab_prog/string-evaluation.html

Wolfie
  • 24,652
  • 7
  • 25
  • 52
  • 1
    I created a [benchmark](https://stackoverflow.com/questions/46179940/performance-of-eval-compared-to-str2func-to-evalulate-a-function-from-a-stri) to compare `eval` with `str2func`. `eval` is 50% slower even for just 1 evaluation. – m7913d Sep 12 '17 at 15:10