Evaluation of input arguments
이전 댓글 표시
In answers to this question it is suggested that one cannot prevent evaluation of function inputs. Namely
sin(x)
??? Undefined function or variable 'x'.
This is the same error you get with
x
Is it possible to overload a set of functions which will allow
x
to not throw an error even when x is undefined. It is not clear to me when and how MATLAB evaluates input arguments. What exactly is happening when I type
x
답변 (1개)
Bottom line - if you try to pass a variable to a function, the variable must exist in the workspace you're calling the function from.
So, executing 'sin(x)' when x does not exist will not work, because you are trying to send non-existant input data to the SIN function.
When you type 'x' at the command line, something similar happens. MATLAB tries to send x to a function that displays x in the command window. If x does not exist, it obviously cannot be sent to a function, similar to the case of sin(x).
You should probably explain why you think you need to be able to work with undefined variables...
댓글 수: 2
Daniel Shub
2012년 10월 15일
Matt J
2012년 10월 15일
I meant "MATLAB" as in the application. The thing that processes your commands.
I should correct what I said before. When you execute a function call in MATLAB, like sin(x), MATLAB first tries to identify the class of x, and then it tries to find a method (in this case SIN) for that class, according to certain rules of precedence. When x does not exist, MATLAB cannot associate the function call with a particular class and so cannot proceed (and gives you an error). Entering 'x' at the command line is the same as entering the function call display(x).
To over-ride this behavior, you would have to over-ride the MATLAB application itself, and the rules it uses to execute expressions. There may be ways to do that, but it's beyond my knowledge.
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!