MATLAB: How to create custom code suggestions for class functions in MATLAB live scripts

autoclasscompletefunctionfunctionsignaturesliveMATLABmemberscriptstaticsuggestions

I am looking at "Customize code suggestions and Completions" at:
And am able to generate function suggestions for regular functions as well as static class functions. The documentation does not mention how to create a suggestion for member class functions. Is this supported?

Best Answer

It is possible to use code suggestions with ordinary class member functions.
The only difference is you must account for the first method argument being a reference to the class.
The first argument passed to a MATLAB class member function is a reference to the object. In that sense, the following two function calls are equivalent:
  1. classObj.func(val)
  2. func(classObj, val)
For more information on this, please see:
When creating the 'functionsSignatures.json', be sure to include an input for the class object.
Here is an example 'functionsSignature.json' snippet for a class which has static and ordinary member functions:
{
"BasicClass.BasicClass":
{
"inputs":
[
{"name":"inputVal", "kind":"required", "type":["numeric"], "purpose":"Constructor with value to initalize with."}
]
},
"BasicClass.printString":
{
"inputs":
[
{"name":"inputString", "kind":"required", "type":["string"], "purpose":"String to print to screen."}
]
},
"BasicClass.multBy":
{
"inputs":
[
{"name":"obj", "kind":"required", "type":["BasicClass"], "purpose":"BasicClass object to run function on."},
{"name":"multVal", "kind":"required", "type":["numeric"], "purpose":"Will multiply the initial value by multVal."}
]
}
}
In the example, "printString" is static, while "multBy" is a traditional member function.
Moreover, once you have written the JSON file, you can also verify it by executing the following command in the MATLAB Command Window:
>> validateFunctionSignaturesJSON
You will find more information about this function in the documentation: