functionSignatures.json : specify filepath
이전 댓글 표시
I like the idea of Matlab function signatures.
How can I specify the file path to search in?
For example, I have a function LoadInputFile , and I want this to default to the directory C://Folder1/Folder2/Folder3, how do I do so? Can I do so both absolute and relative paths?
I have tried a lot of different attempts, all unfortunately failed.
- keywords type / basePath , both failed
- absolute, relative paths
- forward or backward slashes
- single or double slashes
Thank you

"LoadInputFile": {
"_description": "Load a text input file",
"inputs": [
{
"name": "filename",
"kind": "optional",
"type": "filepath=Folder2/Folder3/*.txt",
"basePath": "C://Folder1/Folder2/Folder3/",
"purpose": "some file is now loaded"
}
]
},
답변 (1개)
I suspect that you have a slight misconception of what code suggestions and completions are capable of.
"How can I specify the file path to search in?"
Code suggestions and completions do not really "search" for anything, so your intent here is unclear.
"I have a function LoadInputFile , and I want this to default to the directory C://Folder1/Folder2/Folder3, how do I do so?""
To specify a drop-down value that the user can select you can specify the CHOICES value of the TYPE property:
{
"LoadInputFile": {
"inputs": [
{
"name": "filename",
"kind": "optional",
"type": ["char", "choices={'C://Folder1/Folder2/Folder3/'}"],
"purpose": "some file is now loaded"
}
]
}
}
It is shown to the user in the code suggestions drop-down menu:

Which after being accepted looks like this:

Note that this value is just a suggestion (not a restriction), i.e. the user can modify it to anything they would like.
"Can I do so both absolute and relative paths?"
Of course, you can use any path style that your function was written to accept: code suggestions themselves do not check the class of the input, do not check the existence of a path, or that it is a valid path, or anything else of that ilk. It simply provides some text as an input to your function. Therefore it is your function that needs to check that the path is valid!
To actually check if the input text represents a valid path and to provide a default value use an ARGUMENTS block (or one of its historic equivalents):
댓글 수: 3
Strictly speaking "expression is any valid MATLAB expression that returns a cell of character vectors, string array, or cell of integer values" so you could actually include some code that searches for a path ... but this would be sticking lots of unevaluated MATLAB code in a JSON text string which then gets magically evaluated... uggggh. Not pretty.
covfefe
2026년 1월 17일
"However, what I am looking for is the list of *.txt files in this folder (not the foldername)."
You can do that too. Write a small function that collects the information that you require and returns a cell array of character vectors. For example:
{
"LoadInputFile": {
"inputs": [
{
"name": "filename",
"kind": "optional",
"type": ["char", "choices=myfiles('./*.m')"],
"purpose": "path of the file to load"
}
]
}
}
where
function C = myfiles(P)
S = dir(P);
C = fullfile({S.folder},{S.name});
end
As far as I can tell, the FILE value only searches in the current folder. See also:
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


