How can i define multple syntax for my function?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Walter Roberson
2019년 4월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Creation of Accelerated Executable에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


