editor functionality: check that variable name isn't already a MATLAB function name or keyword?

4 views (last 30 days)
Is it possible that the editor checks automatically in the background, while I am typing, that a by me used variable or handle, etc. name isn´t already exisitent somewhere in MATLAB or a MATLAB toolbox as a function name, keyword or any other import and thus better to reserve than overwrite word? At the moment I am working without toolboxes, but I would like to be prepared as good as possible for the future, and if the editor would not check only against installed functions, but would have a list with generally from The Mathworks available functions, it could be helpful if ALL those existent words become accordingly colored. Furthermore, do the function names from my own code become automatically incorporated in the 'reserved / occupied' name list of the editor (R2013b) for color coding, if my m-files are on a reachable path?
  1 Comment
Marco
Marco on 27 Feb 2014
Nobody would know a solution? Did I not write the text clear enough? I will try in other words:
I would like to see a more helpful editor, an editor which can (activated as a preference option) tell me if any of my own variable names or function names or m-file names, etc., is already in use by some other original THE MATHWORKS stuff. Let´s say, I am using the variable "i" in my script. But I am not aware, that "i" and "j" are already in use by MATLAB for somehting regarding complex numbers. Or let´s say, I am using a function which I name "move". But I am not aware that a function with such name already exists in MATLAB and I therfore without knowing might produce problems which I do not foresee. Let´s say, I am today using a certain function name, but tomorrow I will purchase a toolbox which is already occupying this name...
It is just not a good solution that I have to check each of my names in use with the "which" command first, in order to avoid such conflicts. The editor should be able to do this for me in the background automatically, especially that the editor could know about names in original The Mathworks toolboxes, which I by now have not installed and could not even consider in my "which" tests by now!
Does anybody has an idea, if some editor functionality like this already exits and could tell me how to use it?

Sign in to comment.

Accepted Answer

Sean de Wolski
Sean de Wolski on 27 Feb 2014
  1 Comment
Marco
Marco on 27 Feb 2014
Thanks for the link to the thread. It becomes clear in that thread that my wished functionality is not available by now as a feature in the editor. As best practice it stays recommended to avoid scripts and better use functions, in order to not let variables shadow functions globally, and to keep on checking with the "which -all" function that wished function names are not already occupied.

Sign in to comment.

More Answers (1)

Star Strider
Star Strider on 27 Feb 2014
Edited: Star Strider on 27 Feb 2014
One way (the method I use) is to type the name into the EDITOR window, put the mouse cursor on the word. Then either:
  • right click on it to bring up a pop-up menu, then left click on Help on selection F1
  • press the fn+f1 keys
Both of these bring up the documentation on the word you want information about. If it comes up ‘empty’ — there’s no documentation available on it — then it’s not a MATLAB function or reserved word.
I use this most often to bring up documentation on functions I want information about, but it also works to be sure new variable or function names aren’t already claimed. (It also brings up information on functions I write, a reason to document them with comments just below the function line.)
The iskeyword function also works, but you have to type and run this in the Command Window. (I don’t use this much because it clutters the Command Window.)
  3 Comments
Marco
Marco on 27 Feb 2014
Thanks as well, for your hints!
I at the moment give my projects some abbreviation, which is derived from the topic of the project, i.e. TIATT for "this is a test topic", and then name all my functions with that abbreviation as a prefix in filenames and code, like "TIATT_myfunction.m". It does not look so nice, but makes it less likely that the name is already occupied, or in future becomes occupied, and if it would become the case I could easily in a batch job replace all use of that prefix (in filenames and code) to a new prefix, then. Meanwhile I don´t need so frequently apply the "which" command anymore and just go ahead with my things. But the code looks just not as nice anymore.

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!