I want to chose a function and use it in the code, but have the possibility to chose different functions, is it possible?

2 views (last 30 days)
Bárbara Matos
Bárbara Matos on 1 Nov 2021
Commented: Bárbara Matos on 13 Nov 2021
I am trying to have the possibility to chose different files (which are functions) and use them with a signal. But I need to have the possibility to change the function without changing the code. I tried this, but I don't know if it works. And I don't know why it doesn't work, because if I call the function directly, it is ok!
  1 Comment
Stephen
Stephen on 4 Nov 2021
"But I need to have the possibility to change the function without changing the code"
Then you should be using function handles, rather than messing about with text representation of function names.

Sign in to comment.

Answers (2)


Walter Roberson
Walter Roberson on 1 Nov 2021
fun = str2func(baseStr);
input_dpd = fun(input_signal.x);
  3 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!