Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 4 de Nov. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Nov. de 2021
fun = str2func(baseStr);
input_dpd = fun(input_signal.x);
  3 comentarios
Stephen23
Stephen23 el 4 de Nov. de 2021
Editada: Stephen23 el 4 de Nov. de 2021
The best is to use STR2FUNC, which at least makes the intent clear.

Iniciar sesión para comentar.

Más respuestas (1)

Voss
Voss el 1 de Nov. de 2021
Try replacing your line with eval with the following:
input_dpd = feval(baseStr,input_signal.x);

Community Treasure Hunt

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

Start Hunting!

Translated by