Why is a function sometimes called when I try to use a variable with the same name as the function?
이전 댓글 표시
MATLAB 6.5 (R13) sometimes attempts to call a function when I am trying to use a variable with the same name as that function. There is no mention of this in the documentation.
I have written a function that calls a script. The script creates and initializes several variables. These variables are then used in the function. However, one of the variables has the same name as a MATLAB function, and that function is called when I try to reference the variable. The rules of precedence say that the variable should be used instead of the function.
For example, running the attached function 'foofunc' (given with fooscript below) will give the following error because MATLAB attempts to use the MATLAB function "day" instead of my variable "day" when resolving the statement 'x = day':
ERROR: ??? Error using ==> day
Please enter D.
Error in ==> D:\Applications\MATLAB\R13\work\foofunc.m
On line 3 ==> x = day;
Here is the example function, foofunc.m:
function foofunc
fooscript;
x = day;
Here is the example script file, called fooscript.m:
day = 3;
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!