We all know MATLAB provides tab-completion for filenames used as arguments in MATLAB function like importdata
,imread
. How do we do that for the functions we create?
EDIT:
Displays the files and folders in the current directory.
The name of the file must match the name of the first function in the file. In a script file which contains commands and function definitions. Functions must be at the end of the file. Script files cannot have the same name as a function in the file.
Caution: unsupported hack here.
Take a look at the file toolbox\local\TC.xml in your Matlab installation. This appears to contain the argument type mappings for tab completion. (I found this by just grepping the Matlab installation for "imread" in R2009b.)
Adding this line inside the <TC>
element will get you tab-completion of file names for each of its arguments.
<binding name="importdata" ctype="FILE"/>
This requires modifying the Matlab installation in place. For some of the other files in toolbox/local, like classpath.txt, you can override them by placing modified copies in the directory you start Matlab from, but this didn't work for TC.xml for me.
There is no supported way to add your functions to the argument Tab completion, but one trick I use is to put a "!" in front of the command so it is treated like a system command. Tab will then complete file paths. Once my MATLAB command is done, I home to the beginning of the line, delete the "!" and press enter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With