Why do I get the error message " ??? Error using ==> inlineeval "?
조회 수: 3 (최근 30일)
이전 댓글 표시
Why do I get the error message " ??? Error using ==> inlineeval " when trying to evaluate h(3) where h(x) is the INLINE function g(f(x)) ?
For example, when the INLINE function is defined as follows, g(f(3)) is evaluated in MATLAB but h(3) returns an error message.
f = inline('x.^2')
g = inline('3*x')
h = inline('g(f(x))')
h(3)
??? Error using ==> inlineeval
Error in inline expression ==> g(f(x))
??? Undefined function or variable 'f'.
채택된 답변
MathWorks Support Team
2009년 6월 27일
This is happening because INLINE functions are objects and not actual functions. Thus, they do not have the same scope rules as functions. When the following is created :
h = inline('g(f(x))')
h =
Inline function:
h(x) = g(f(x))
The INLINE constructor recognizes that "x" is a variable, but it assumes that f and g are functions, while the user actually meant them to be variables f and g. When the constructor goes to evaluate h, it has the input x and looks for functions g and f but isn't able to find them (for simplicity we assume there are no functions f or g on the path ). The variables f and g exist, however they exist as INLINE objects in the MATLAB workspace but not in the function "h".
Thus users will have to indicate to MATLAB what f and g are. First, in h, declare that f and g are variables as shown in the following code:
h = inline('g(f(x))','x','f','g')
h =
Inline function:
h(x,f,g) = g(f(x))
Then to execute, pass values to h for f and g :
h(3,f,g)
ans =
27
Please Note: This works as of MATLAB 6.0 (R12). However in MATLAB R11 there was a bug in "subsref" (the function that makes f(...) evaluate the same as feval(f,...)) for INLINE objects. This caused the last line to generate errors. To workaround this bug in MATLAB R11, you will need to do the following :
h = inline('feval(g,(feval(f,x)))','x','f','g')
h(3,f,g)
ans =
27
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!