Class Method's 'IntelliSense' & 'help(f1) description' doesn't show - Is MathWorks working to add this feature?
4 views (last 30 days)
Show older comments
There are 2 features that would be very helpful, which apear to be absent from Matlab Class Objects. Note that I am using the latested released Matlab version R2024a.
1) For the matlab code IntelliSense to show the input arguments of a class method when typing out the arguments, both when calling the method from the Command Window and when typing out the method-call in a script or another function/method. From what I have been able to see, this feature only works for matlab functions, and the contructor for a class, but not any of the other methods (other than the constructor) in a class. This is true also when typing out the method within the same class .m file, to say call a method from another method of the same class. Below is an example of this IntelliSense feature working for a class constructor.
2) For the help button for a class method to show the method's description, located below the deceration of the method, to apear in the help (F1) window, similar to how function descriptions apear in the same help window. Below you can see the class method named "FindAnAvailableOperator()" when when I open the help window for this function, the help window only tells me that this "is a function" and doesn't contain the description I would expect to find, which is "(Operators,Model,currentDateTime)"
1 Comment
dpb
on 2 Aug 2024
I use classes rarely, so am not particularly good one to comment, but my experience with the one class module I do use which defines a bunch of static methods for Excel activeX interaction is that intellisense works both to find the methods in the class and then to display the argument list in both the command window and the editor (albeit the response is sometimes so slow that one gives up and goes on before it is actually displayed, but it is implemented).
The F1 Help also brings up the highlighted help although for the class method one has to highlight both the class and the method which is somewhat of a nuisance since it takes selecting over the dot separator and therefore, at least two operations. But, the method without the class is unrecognized; trying to have intellisense parse even more would slow things down probably to the point of total uselessness.
I'm still running R2021b here for other reasons...
Accepted Answer
Githin George
on 28 Aug 2024
Hello Cody,
I would say there are 2 separate issues which are to be considered here.
- An option to enhance the tab-complete feature for MATLAB Classes and functions.
- Documentation text for the member functions of a MATLAB Class.
For the first issue, you could try using the "functionSignatures.json" file to describe the json schema will be used to provide the tab-complete options for each function. I've shown an example below.
File 1: "MyClass.m"
classdef MyClass
properties
% Define some properties for the class
Operators
Model
end
methods
% Constructor for MyClass
% obj = MyClass(Operators, Model)
% Initializes the class with given operators and model.
function obj = MyClass(Operators, Model)
obj.Operators = Operators;
obj.Model = Model;
end
function output = FindAnAvailableOperator(obj, currentDateTime)
% FINDANAVAILABLEOPERATOR Find an available operator.
% [output] = FindAnAvailableOperator(obj, currentDateTime)
% This method finds an available operator based on the provided current date-time.
% Method implementation
% Here, you would add logic to find an available operator.
arguments
obj
currentDateTime
end
output = []; % Placeholder for actual implementation
end
function obj = AddOperator(obj, newOperator)
% ADDOPERATOR Add a new operator to the list.
% obj = AddOperator(obj, newOperator)
% This method adds a new operator to the existing list of operators.
obj.Operators = [obj.Operators, newOperator];
end
function DisplayModel(obj)
% DISPLAYMODEL Display the current model.
% DisplayModel(obj)
% This method prints the current model to the command window.
disp('Current Model:');
disp(obj.Model);
end
end
end
File 2: "functionSignatures.json"
{
"MyClass": {
"FindAnAvailableOperator": {
"inputs": [
{
"name": "currentDateTime",
"kind": "required"
}
],
"outputs": [
{
"name": "output"
}
]
},
"AddOperator": {
"inputs": [
{
"name": "newOperator",
"kind": "required"
}
],
"outputs": []
},
"DisplayModel": {
"inputs": [],
"outputs": []
}
}
}
But please note that this functionality is meant primarily for the MATLAB Editor (M scripts and MLX scripts) and may not work well in the MATLAB Command Window. For more information about Customizing Code Suggestions and Completions, you may refer to the following documentation page:
As for the second issue, I've verified that F1 help text generates the information provided in the comments below the declaration of the member function. In the case of "MyClass", F1 help text is generating the provided description for all 3 member functions. The function "help MyClass.AddOperator" is also generating the same text which is the expected outcome.
For more info on "help" function refer to the documentation page below:
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!