How to doc() a command which is overloaded by multiple toolboxes

8 views (last 30 days)
The evaluate() command has a version in both the the Curve Fitting Toolbox and in the Optimization Toolbox. How does one use doc() to resolve the ambiguity and bring up the documentation of the desired version?

Accepted Answer

Steven Lord
Steven Lord on 19 Sep 2023
The evaluate function in both those products (and a few others) is a method of different types of objects.
which -all evaluate
evaluate is a built-in method % matlab.io.xml.dom.Document method /MATLAB/toolbox/curvefit/curvefit/@fittype/evaluate.m % fittype method /MATLAB/toolbox/ident/nlident/@idNeuralStateSpace/evaluate.m % idNeuralStateSpace method /MATLAB/toolbox/ident/nlident/@idnlfun/evaluate.m % idnlfun method /MATLAB/toolbox/pde/@pdeInterpolant/evaluate.m % pdeInterpolant method
In Curve Fitting Toolbox, evaluate is a method of the fittype object.
help fittype.evaluate
EVALUATE Evaluate a FITTYPE object F = FEVAL(FITOBJ,A,B,...,X) evaluates the function value F of FITOBJ with coefficients A,B,... and data X. [F, J] = FEVAL(FITOBJ,A,B,...,X) evaluates the function value F and Jacobian J, with respect to the coefficients, of FITOBJ with coefficients A,B,... and data X.
If I used doc fittype.evaluate it will bring up the documentation page for that method. In my MATLAB Online session that method does not have a dedicated function reference page so it brings up the help text instead.
The evaluate method for OptimizationExpression objects didn't show up in my first which call because that class was not loaded in memory at the time I called which. Let me make one and you'll see that now the Optimization Toolbox object methods are listed:
x = optimvar('x');
y = optimvar('y');
prob = optimproblem;
prob.Objective = -x -y/3;
which -all evaluate
/MATLAB/toolbox/curvefit/curvefit/@fittype/evaluate.m % fittype method evaluate is a built-in method % matlab.io.xml.dom.Document method /MATLAB/toolbox/shared/adlib/+optim/+problemdef/@OptimizationExpression/evaluate.p % optim.problemdef.OptimizationVariable method /MATLAB/toolbox/shared/adlib/+optim/+internal/+problemdef/@ExpressionForest/evaluate.p % optim.internal.problemdef.ExpressionForest method /MATLAB/toolbox/shared/adlib/+optim/+internal/+problemdef/Uminus.p % optim.internal.problemdef.Uminus method /MATLAB/toolbox/shared/adlib/+optim/+internal/+problemdef/Operator.p % optim.internal.problemdef.UnaryOperator method /MATLAB/toolbox/shared/adlib/+optim/+internal/+problemdef/Rdivide.p % optim.internal.problemdef.Rdivide method /MATLAB/toolbox/shared/adlib/+optim/+internal/+problemdef/Minus.p % optim.internal.problemdef.Minus method /MATLAB/toolbox/ident/nlident/@idNeuralStateSpace/evaluate.m % idNeuralStateSpace method /MATLAB/toolbox/ident/nlident/@idnlfun/evaluate.m % idnlfun method /MATLAB/toolbox/pde/@pdeInterpolant/evaluate.m % pdeInterpolant method
Now if I ask for help:
help optim.problemdef.OptimizationExpression.evaluate
optim.problemdef.OptimizationExpression/evaluate - Evaluate optimization expression Use evaluate to find the numeric value of an optimization expression at a point. Syntax val = evaluate(expr,pt) Input Arguments expr - Optimization expression OptimizationExpression object pt - Values of variables in expression structure Output Arguments val - Numeric value of expression double Examples openExample('optim/EvaluateOptimizationExpressionAtPointExample') openExample('optim/EvaluateObjectiveFunctionAtSolutionExample') See also solve, infeasibility, OptimizationExpression Introduced in Optimization Toolbox in R2017b Documentation for optim.problemdef.OptimizationExpression/evaluate doc optim.problemdef.OptimizationExpression/evaluate
and if I asked for doc on that method name in MATLAB Online it would bring up the page in the online documentation that I linked above.
This is documented in the help and documentation for the doc function. [Which I'd guess is one of the less frequently referenced documentation pages.]
"Some classes and other packaged items require that you specify the package name. Events, properties, and some methods require that you specify the class name. Separate the components of the name with periods, such as:"
Also see the "Class and Method Reference Pages" example on that doc page.

More Answers (0)

Categories

Find more on Toolbox Distribution in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!