Why is a function sometimes called when I try to use a variable with the same name as the function?
Afficher commentaires plus anciens
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;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Code Performance dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!