Autocomplete of filenames for function input params
Ältere Kommentare anzeigen
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 Kommentar
Luke Winslow
am 24 Jun. 2011
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.
Akzeptierte Antwort
Weitere Antworten (4)
There you find instructions for editing:
edit(fullfile(matlabroot,'toolbox/local/TC.xml'))
4 Kommentare
Walter Roberson
am 24 Jun. 2011
Neato!
Miro
am 7 Sep. 2011
Tyvaughn Holness
am 9 Mär. 2020
Worked on 2015a! The .json method did not
Yair Altman
am 11 Mär. 2020
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
am 24 Jun. 2011
1 Stimme
As of 2010a this was not possible at the user level. I have not heard any evidence that the situation has changed since.
AMM
am 5 Mai 2020
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
am 10 Mär. 2023
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 Kommentare
Matt J
am 19 Feb. 2025
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.
Kategorien
Mehr zu JSON Format finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!