What would you do?

조회 수: 14 (최근 30일)
Kye Taylor
Kye Taylor 2013년 7월 3일
Suppose you have a string like
rhs = 'x*cos(x)/(t+1)';
and that you want to create a function handle... would you do
fHandle = str2func(['@(t,x)',rhs])
or
fHandle = eval(['@(t,x)',rhs]);
or
?
Can you explain why?

채택된 답변

Chad Gilbert
Chad Gilbert 2013년 7월 3일
I'd tend to choose str2func, merely because it makes it more obvious what I'm anticipating as an output.
  댓글 수: 1
Kye Taylor
Kye Taylor 2013년 7월 8일
Good thought. Thanks.

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

추가 답변 (1개)

Shashank Prasanna
Shashank Prasanna 2013년 7월 3일
Don't use eval - EVER!
There is a whole documentation page that should answer 'why?'
  댓글 수: 1
Kye Taylor
Kye Taylor 2013년 7월 8일
Thanks for the pointer!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by