Undefined Function or Variable but the variable is in fact Defined

So clearly k is defined, but Matlab keeps telling me it is not defined. What is going on?
>> k=1
k =
1
>> f_n
f_n =
@(r,n)sqrt(pi/(2*k*r))*besseli(n+.5,k*r)
>> f_n(1,1)
Undefined function or variable 'k'.
Error in @(r,n)sqrt(pi/(2*k*r))*besseli(n+.5,k*r)

 채택된 답변

Sean de Wolski
Sean de Wolski 2016년 3월 21일

1 개 추천

The function was defined before k. When the anonymous function is created, it grabs a static snapshot of the workspace and does not update. To incorporate k, just rerun the command to create the function handle.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

질문:

2016년 3월 21일

답변:

2016년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by