Autocomplete of filenames for function input params
古いコメントを表示
When using matlab functions such as "load" or "save" you can double-tab to autocomplete filenames that are in the path. However, when I have written my own functions that take filename strings as input this feature is not available (Which is reasonable since all functions shouldn't assume filename input).
I wonder if it is possible to somehow "hint" your own functions that they should try to autocomplete input parameters by searching over files in your matlab path.
1 件のコメント
Luke Winslow
2011 年 6 月 24 日
Wow, this is *exactly* the same question I had. I haven't been able to figure it out, but I did look into existing matlab functions, and it offers no help.
For example, the 'importdata' function auto-completes file names, but it doesn't seem to do anything special to the input. It immediately puts the first argument into a variable called FileName, but I tried that and it doesn't seem to make a difference. I'd really like to know the answer to this as the auto-complete is super useful.
採用された回答
その他の回答 (4 件)
There you find instructions for editing:
edit(fullfile(matlabroot,'toolbox/local/TC.xml'))
4 件のコメント
Walter Roberson
2011 年 6 月 24 日
Neato!
Miro
2011 年 9 月 7 日
Tyvaughn Holness
2020 年 3 月 9 日
Worked on 2015a! The .json method did not
Yair Altman
2020 年 3 月 11 日
As Nicholas Mati answered below, Matlab switched from using TC.xml to the JSON mechanism around 2015-2016. The original question was made in 2011; my article about the undocumented TC.xml mechanism was posted in 2010. This worked well until 2015-ish, but for newer Matlab releases you need to use the JSON mechanism. Nothing lasts forever...
Walter Roberson
2011 年 6 月 24 日
1 投票
As of 2010a this was not possible at the user level. I have not heard any evidence that the situation has changed since.
AMM
2020 年 5 月 5 日
Is there a way to use wildcards other than asterisks for filenames in a JSON block like
{"name":"filename", "kind":"required", "type":[["file=*.txt,*.asc,*.*n"], ["folder"], ["char"]]}
I ask because I want to match files with suffixes of the form filename.06n, where the two characters preceding the final "n" can be any digits, but not anything else. In UNIX I would use something like
file=*.txt,*.asc,*.*[0-9][0-9]n
... but that doesn't work at all in my functionSignatures.json.
Tracy Fulghum
2023 年 3 月 10 日
A user hack is to use the ls function as a wrapper around your filename argument, and exploit the autocomplete of the ls function, as in
myFunction(ls('aFileName<tab>'), ...)
The ls function will autocomplete whatever file name you're looking for and return a string listing it.
2 件のコメント
Matt J
2025 年 2 月 19 日
This unfortunately only works if aFilename<tab> is located in the current folder. Also, it doesn't appear to support command syntax:
>> myFunction ls('aFileName<tab>')
I believe the limitation on current folder can be addressed by wrapping with
fullfile()
instead of
ls()
This should allow tab completion from anywhare on the filesystem and return the path and file exactly as tab-completed.
However, I don't think this addresses the limitation regarding command syntax.
カテゴリ
ヘルプ センター および File Exchange で JSON Format についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!