How can i define multple syntax for my function?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I would like to automatically create documentation for my MATLAB function using live function, so i can call
doc function_name
to show the generated doc, like a real MATLAB function. How can i define multiple way of calling my function?
My function is:
function [x, output, grafico] = bisezione(f, x0, TOL_utente, NMAX_utente)
x, f and x0 are needed for my function to work, while output, grafico, TOL_utente and NMAX_utente are optional. I would like to show all the possible syntax (like in the fzero MATLAB function reported in the image), but generating the live function only allows me to put one function for each file. Is there a solution?

end
0 Commenti
Risposte (2)
Walter Roberson
il 3 Apr 2019
You only define the function once: you just put multiple lines in the initial contents so that the different possibilities are shown to the user when they use help.
You examine the number of inputs with nargin() or you use exist('options','var') to see if any value was passed in. See also https://www.mathworks.com/help/matlab/ref/inputparser.html for more complicated cases.
if nargin < 2
error('Need at least 2 parameters')
end
if nargin < 3 || isempty(TOL_utente)
TOL_utente = 1e-7; %default value
end
if nargin < 4 || isempty(NMAX_utente)
NMAX_utente = 100; %default value
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Creation of Accelerated Executable in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


