How can I create custom code suggestions for class functions in MATLAB live scripts?

9 views (last 30 days)
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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 May 2019
Edited: MathWorks Support Team on 23 May 2019
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:

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!