필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Stephen23
Stephen23 2021년 11월 4일
"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.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 1일
fun = str2func(baseStr);
input_dpd = fun(input_signal.x);
  댓글 수: 3
Stephen23
Stephen23 2021년 11월 4일
편집: Stephen23 2021년 11월 4일
The best is to use STR2FUNC, which at least makes the intent clear.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Voss
Voss 2021년 11월 1일
Try replacing your line with eval with the following:
input_dpd = feval(baseStr,input_signal.x);

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by