functionSignatures.json : specify filepath

28 views (last 30 days)
covfefe
covfefe about 12 hours ago
Edited: covfefe about 8 hours ago
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"
}
]
},

Answers (1)

Stephen23
Stephen23 about 1 hour ago
Edited: Stephen23 about 1 hour ago
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):
  2 Comments
Stephen23
Stephen23 13 minutes ago
Edited: Stephen23 6 minutes ago
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
covfefe 10 minutes ago
@cov@Stephen23, thank you for the prompt and detailed answer.
With your changes, I can now fill a hardcoded foldername: C://Folder1/Folder2/Folder3.
However, what I am looking for is the list of *.txt files in this folder (not the foldername).
Adding a *txt filter just changes the string:
"LoadTextFile": {
"inputs": [
{
"name": "filename",
"kind": "optional",
"type": ["char", "choices={'C://Folder1/*.txt'}"],
"purpose": "some file is now loaded"
}
]
}
Instead, if I use filepath, then I can get the file list (but only in the current directory, not in C://Folder1)
"type": "filepath=*.txt",
Maybe I need a combination of both, something along the lines of this?
"type": ["filepath", "choices={'C://Folder1/*.txt'}"],

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!