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

13 ビュー (過去 30 日間)
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 件のコメント
Marco
Marco 2014 年 2 月 27 日
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?

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 2 月 27 日
  1 件のコメント
Marco
Marco 2014 年 2 月 27 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Star Strider
Star Strider 2014 年 2 月 27 日
編集済み: Star Strider 2014 年 2 月 27 日
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 件のコメント
Star Strider
Star Strider 2014 年 2 月 27 日
Good point. Another reason I don’t use it much.
Marco
Marco 2014 年 2 月 27 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by