I'm writing MATLAB functions for use by others. I know how to use nargin
, varargin
, etc. to create a function with variable number of inputs.
The function I'm currently writing is recursive and I need to pass an argument to handle the recursion, but the user should never pass anything in for that argument (or they should pass in the non-intuitive starting value, but they don't need to be distracted by that). I want to 'hide' this argument from the user, so that when they're writing code to use this function and MATLAB pops up that little yellow window that tells them what arguments the function takes, it just prompts them for the arguments they care about.
To be more explicit, when you type rand(
, MATLAB pops up a little help window with
rand()
rand(n)
rand(sz1,...,szN)
...
My function recursively builds a matrix and I've currently defined it this way:
function ret = M(arg1, arg2, HideThisRecursiveArgument)
% code that sets the starting value for HideThisRecursiveArgument when it's not passed
% code that calls M(...) again with a different recursion value
end
When the user types M(
, I want MATLAB's little help popup to display the usage as:
M(arg1, arg2)
(arg1
and arg2
are named in a self descriptive manner, so this would be a sufficient 'help page' for my function.)
How can I document this usage so MATLAB's function usage help popup will display this to the user?
If I use varargin, the user might get distracted/confused by trying to figure out what else could be passed in, so that's unsatisfactory. I've tried defining my function with 2 arguments and then looking for a 3rd when it's called, but MATLAB doesn't like that.
Edit
I've found the Add Help for Your Program page, and if the user uses the help
command or clicks the More Help... link in that yellow usage popup, I can control what they see there, but this doesn't tell me how to control what appears on the usage popup.