Is it possible to use function name as name of a variable?

4 views (last 30 days)
for example sin = 1 is allowed, however I do not know is it correct or not? or myfunc = 2, if I have previously defined a myfunc() function. For example in case of sin = 1, sin() is also accepted, since sin is a scalar ([1]), but what if myfunc() has no parameters, this causes ambiguity?
  1 Comment
Stephen23
Stephen23 on 25 Feb 2015
Edited: Stephen23 on 25 Feb 2015
It is a really really bad idea to do this:
sin = 1
because then you cannot call the function sin. Calling sin(1) gets the first element of the variable named sin, but because of this (bad) assignment it now has nothing to do with the function sin and only refers to the variable. Really bad idea. Just because something is possible does not make it a good idea to do it.

Sign in to comment.

Answers (1)

Matt J
Matt J on 1 Feb 2015
Edited: Matt J on 1 Feb 2015
You can always assign any name to variable, but once you do, you are cut off from using the same name to invoke a function, until the variable is cleared or goes out of scope.

Community Treasure Hunt

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

Start Hunting!