How can I display function hints for methods in a class?

22 views (last 30 days)
For example,
I wrote a class named elmnet (code below):
classdef elmnet
properties
% Some properties
end
methods
function this = elmnet(Neurons, varagin)
% Constructor code
end
function this = estimate(this, Input, Output)
% Some code
end
end
end
when I try to create an elmnet object, Matlab hints me the correct arguments it uses.
Since the object is created and stored in a variable, in this case 'net', it does not shows correctly the arguments for its methods:
How can i make the methods within a class present me correct hints for calling them?
  3 Comments
Ihab Abboud
Ihab Abboud on 22 Mar 2023
any news on this. it would be great is this is fixed

Sign in to comment.

Answers (5)

Tony
Tony on 23 May 2016
Edited: Tony on 23 May 2016
Have the same issue, function hints for a user-defined class method are not useful.
A slightly different issue, could be the same, though; is for user-defined functions -- the function hint only shows one signature.
Is it possible to change which signature is shown, or show all signatures in user-defined function hint ?
The example code below only produces one function hint, for addme(a,b) signature, which is not sufficient, can this be changed ?
function c = addme (a,b)
% ADDME Add two values together.
%
% C = ADDME(a) adds a to itself.
%
% C = ADDME(a,b) adds a and b together.
%
% See also SUM, PLUS.
c = a + a; %TODO: finish code

Simon Parten
Simon Parten on 3 Aug 2016
Bump this ... it would be an extremely useful feature.

Jan Kappen
Jan Kappen on 31 Aug 2016
This is an really necessary feature!
  3 Comments
Paul Meinert
Paul Meinert on 12 Jul 2018
Indeed, the functionSignatures.json file only seems to work inside of Matlab "live scripts", not inside the regular command window.
Any help on getting function hints to work inside of the command window, and for class methods would be greatly appreciated. This seems like a major omission or maybe we're all missing something ?

Sign in to comment.


Tom Shlomo
Tom Shlomo on 6 Jan 2020
Any news on this? perhaps something changed with the recent introduction of the arguments block?

Nicholas Ayres
Nicholas Ayres on 17 Mar 2020
Edited: Nicholas Ayres on 17 Mar 2020
It seems I misenterpreted the question. I will leave my previous answer below, but if you DO write the signatures json, you could potentially put "choices={'inputName'}" in the position and then hitting tab will input the input name for the user to check. (and then delete to put in the actual input).
-------------------------------------------------------------------------------------------------------
I've cracked it! It's a little awkward, but I've cracked it.
This method only works with function notation like:
func(obj,inputs)
and NOT dot notation:
obj.func(inputs)
If you only have one function with this name (whether in another class or just a function), all you need to do is write the functionSignature.json as if the function were NOT a member of the class and enforce that the FIRST input to your function is your class. Like so:
{
"func":
{
"inputs":
[
{"name":"obj", "kind":"required", "type":"myClass"},
...
]
}
}
If you wish to use the same function name for multiple classes (or just a function name), you must use the "mutuallyExclusiveGroup" functionality.
{
"func":{
"inputs":[
{"mutuallyExclusiveGroup":
[
[
{"name":"obj","kind":"required","type":"myClass"},
...
],
[
{"name":"obj","kind":"required","type":"testClass2"},
...
]
]
}
]
}
}
Now, whenever you type your function name like so:
func(
and tab complete the first entry, all variables in your workspace matching any of the potential classes will be listed. Once this first entry is selected, the following suggestions will only be for the specific mutally exclusive group to which the class of your object belongs.
If you HAVE to use dot notation, i.e.:
obj.func(inputs)
then you will have to just move the obj part out the front after you've written the statement in function notation.
The bit that I consider awkward about this is that the signature is tied to just the function name and not the class, meaning that if you wish to:
  • Change a function name within a class, you have to move the relevant mutually exclusive block to a new function block, rather than just changing the function name.
  • It is more difficult to locate a mutually exclusive block when deleting/editing.
I have tried testing a load of other methods that SHOULD make sense (e.g. setting the function to be something like "myClass.func"), but these do not work.
If you have any questions, please ask as sometimes I need a little more prompting to get my point accross!!

Community Treasure Hunt

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

Start Hunting!