Tab-completion of filenames as arguments for MATLAB scripts

耗尽温柔 提交于 2019-11-28 21:17:08

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.

For Matlab 2016a and above :

The file Tc.xml is not present in Matlab 2016a onwards. It uses a .json (Java Script Object Notation) file to achieve the same. A simple example of this can be as follows.

Suppose you have a Matlab function file called myFunction.m. Furthermore, suppose that this function needs files with extension .ext as input and you want the tab-completion to show all possible input options for this function. Then, write the following content in a file and name it functionSignatures.json.

{
"myFunction":
{
  "inputs":
  [
    {"name":"filename", "kind":"required", "type":"filepath=*.ext" }
  ]
}
}

Place this file in the same directory as myFunction.m file. Now, restart Matlab.

What this file does : While typing in the function input, upon pressing tab, you will see a list of files with the extension .ext popping up. If you want all the files to be shown in tab completion popup irrespective of their extension, then replace "type":"filepath=*.ext" with "type":"filepath" in the file functionSignatures.json.

Source : https://www.mathworks.com/matlabcentral/answers/306157-how-to-configure-tab-completion-for-my-function-in-matlab-2016#answer_237857

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!