Tab Completion is a popup that can be found in both the Command Window and the Editor. After you type a key (or a few) you can hit the tab key and a popup will appear and show you all of the possible completions, including variable names and figure properties. If you are a horrible typist like I am, this can save you from having to type the whole string and hit backspace over the typos. It is also useful when you just can’t remember the functionname. I find myself sometimes thinking, “I know that the function I want to call here starts with ’str’…”. Hitting tab in this case shows me all of the functions that start with that string.
Once the popup has appeared, you can continue to type to narrow your choices or you can arrow to the correct item and then hit tab or enter to insert that completion into the window.
Some long-time users of MATLAB will fondly recall the old days when the completions printed to the window. Hitting tab 2x would display any completions in the output area. If your fingers still try to do this, there is a preference in the “Keyboard” section of Preferences called “Tab key narrows completions”. This preference changes the behavoir of tab completion to work more like the old tab completion. When the popup is showing, you can type a few keys and hit tab again to narrow the completions. Hit enter to select a completion.
Do you use the tab completion popup in the default mode or in the “tab narrows” mode?
Posted by Kristin Thomas
Kristin is a developer on the MATLAB Desktop team. She works primarily on the Command Window when she is not throwing herself down a mountain on her snowboard.
Hi!
I am using Matlab classes and objects. Let say I have a function myfunction.m in some class directory @myclass. If I type “edit myfu” and then hit tab, I see “No completions found”. However, if I enter “edit myfunction” and hit return, the function is opened.
I think checking the whole path for the tab completion might take too long, but the subdirectories of the current directory should be included.
Regards
Markus
Thanks Markus. I’ll look into this. Which release are you using?
I am using Matlab version 7.3.0.267 (R2006b)
Tab completion is a fabulous feature. I do most of my work in Stateflow. Are there any plans to add a similar feature to the Stateflow editor? It could be context driven and suggest items that would fit in. eg, hitting a tab while initially entering a transition brings up a list of all defined events.
Cheers,
Tehn Yit Chin
Australian Arrow P/L.
Not that I am aware of. That doesn’t mean that someone isn’t working on it, or thinking about it… just that I haven’t heard anything about that. I’ll put in an enhancement request to the Stateflow team. Thanks for the suggestion.
I strongly support the request about tab completion in Stateflow. Especially since busses were introduced to Stateflow, that would be a very helpful feature.
Tab completion is what differentiates good environments from bad environments. However, why doesn’t the matlab editor allow, as an option, tab-completion of variables and function declared in the file but not in the current workspace? All serious coding environemts provide that feature these days, even the ones that cost less than a full months salary.
Sincerely
Daniel Armyr
What release of matlab supports Tab Completion in the Editor window?
I’m using R14sp3 and I can’t seem to find how to configure it.
Hi Elad,
Tab completion was introduced into the MATLAB Editor in version 7.2 (R2006a) (one release after yours), though it had been around longer in the Command Window.
Check out the release notes for more detailed information on the evolution of this feature.
-Ken
I am using Matlab classes. Let say I have a function fcea.m and fceb.m in some class directory @myclass. In workspace there is instance C of myclass.
I implemented method ‘methods.m’ and place it into directory @myclass too. This method returns only {’fcea’ ‘methods’}’ cell.
If I call:
>> methods(C)
I obtain a cell above mentioned, which is a different result then if I call
>> methods(’myclass’)
where I obtain a list of all methods fcea, fceb, methods.
If I use Tab completion in the form >> C.’tab’ I obtain ‘myclass’ methods from methods called in this form “methods(’myclass’)”. Is any way how to change it to call methods in this form: “methods(C)”?
Or how can I modify list of methods available in tab completion for a class?
My Matlab version 7.4.0.287 (R2007a)
Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 2)
Thx
Michal
Hi Michal,
I had to consult the MATLAB OOPS experts for this one! Unfortunately, the short answer to your question is no - there is no way to have tab completion call your version of methods. The good news is that there will soon be a much more robust class system in MATLAB.
Here’s the detailed reason of why this won’t work for you. Let me first restate your problem:
You have a class with three methods, like this:
myClass / | \ fcea fceb methodsYour intention by overriding methods (a built-in MATLAB function) is to hide fceb (i.e. to make it private).
There are two ways MATLAB can determine what methods your class contains. One is by calling the methods function with the string name of your class. This technique results in a listing of ALL methods in your class, so in your case:
{’fcea’ ‘fceb’ ‘methods’}
You can also use the methods(yourObject). This technique dispatches directly to your overloaded implementation of methods.
In the case of tab completion, the first technique described above is used to determine what methods are available.
-Ken
Than you Ken,
I summarize it in in this post:
http://www.tim.cz/en/nfaq/matlab-simulink/tab-completion.php
I’m expected to new class system in Matlab.
Best
Michal
Hi Michal,
Thats a great article on tab completion for MATLAB classes. I like your clever workaround to the problem you mentioned above!
-Ken
Hey guys,
Thanks for this blog :)
Quick question (though suspect I know the answer): Can I somehow tell MATLAB that the input argument to my function is going to be a filename so that it’ll allow me to use tab completion in the Command Window?
Cheers,
Joachim
Joachim,
MATLAB does not currently have support for users to add tab completion to their files. I suggest you request an enhancement from our web form (requires login):
http://www.mathworks.com/support/service_requests/contact_support.do
If you want to specify a file as an argument, there is a dirty trick you can use in the Command Window. The “!” (bang) operator is shorthand for issuing the system command. You can use this to trick the command window into thinking you are typing a shell command, use the file completion and then go back to the beginning of the line and delete the “!”.
So if you wanted
just use:
and so on.
But please, enter the enhancement request, and be specific as possible about your particular use case.
Thanks,
Mike
Hah, clever trick with the bang. I’ll be using that occasionally, thanks.
But I will also submit an enhancement request. Thanks for the reply!
Joachim
Hi, I have to agree with Daniel. What’s up with no v7.2+ Editor support for tab completion for variables in the file being edited, but not in the workspace?
Does anyone know of an Eclipse plugin for Matlab, or does Matlab not play well with open source? It would be such a relief to use a real editor.
Sincerely,
Peter
Peter,
Since M-files are just text files you can edit them anywhere. There may even be someone who has approximated syntax highlighting and if/end completion, etc for eclipse, but the big advantage of the MATLAB editor is cell-mode, publishing, debugging, and execution, which would be difficult to do outside of MATLAB.
I am interested in hearing why you think our editor is not a “real editor,” and what its limitations are within your workflow. You can email me at michael.katz@mathworks.com.
Hi Peter,
I can assure you we are working hard on making tab-completion work in the Editor.
We’d love to hear what you think is missing from the MATLAB Editor, as we’re constantly striving to improve it.
Feel free to email Mike or myself (ken.orr@mathworks.com).
-Ken
To Daniel and Peter, regarding tab completion on variables defined in files in the editor. This is one of those places where MATLAB’s loose interactivity makes it much harder for MATLAB to figure out your intentions through static analysis. Other languages require that you declare variables before they are used, so it’s fairly trivial to know what’s what.
That said, we’ve got some awfully clever people working on MATLAB. Perhaps if I tell them it can’t be done, we’ll see something soon :)