文件名的制表符补全作为 MATLAB 脚本的参数

发布于 2024-08-13 14:07:51 字数 237 浏览 4 评论 0原文

我们都知道 MATLAB 为 MATLAB 函数中用作参数的文件名提供制表符补全功能,例如 importdataimread。我们如何为我们创建的函数做到这一点?

编辑:

alt text

显示当前目录中的文件和文件夹。

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:

alt text

Displays the files and folders in the current directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

汐鸠 2024-08-20 14:07:51

注意:这里不支持 hack。

查看 Matlab 安装中的文件 toolbox\local\TC.xml。这似乎包含用于制表符完成的参数类型映射。 (我通过在 R2009b 中 grep Matlab 安装中的“imread”找到了这一点。)

元素中添加此行将为您提供每个参数的文件名的制表符补全。

<binding name="importdata"        ctype="FILE"/>

这需要修改 Matlab 安装。对于 toolbox/local 中的其他一些文件,例如 classpath.txt,您可以通过将修改后的副本放置在启动 Matlab 的目录中来覆盖它们,但这对我来说不适用于 TC.xml。

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.

微凉 2024-08-20 14:07:51

没有受支持的方法可以将函数添加到参数 Tab 自动完成中,但我使用的一个技巧是添加一个“!”在命令前面,因此它被视为系统命令。然后 Tab 将完成文件路径。 MATLAB 命令完成后,我回到该行的开头,删除“!”并按回车键。

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.

风月客 2024-08-20 14:07:51

对于 Matlab 2016a 及更高版本:

文件 Tc.xml 在 Matlab 2016a 及更高版本中不存在。它使用 .json (Java 脚本对象表示法)文件来实现相同的目的。一个简单的例子如下。

假设您有一个名为 myFunction.m 的 Matlab 函数文件。此外,假设此函数需要扩展名为 .ext 的文件作为输入,并且您希望制表符补全显示此函数的所有可能的输入选项。然后,将以下内容写入文件中,并将其命名为 functionSignatures.json

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

将此文件放在与 myFunction.m 文件相同的目录中。现在,重新启动 Matlab。

此文件的作用:在函数输入中键入时,按 Tab 键,您将看到弹出一个扩展名为 .ext 的文件列表向上。如果您希望所有文件都显示在选项卡补全弹出窗口中,无论其扩展名如何,请将 "type":"filepath=*.ext" 替换为 "type":"filepath"< /code> 文件 functionSignatures.json 中。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文