Private functions serve a valuable purpose when you wish to restrict the accessibility of a function.
In numerous instances, a single function may require access to one or more auxiliary functions.
when a single auxiliary function is used by multiple functions, place the auxiliary functions in a subdirectory named "private" inside the directory that contains the functions requiring access to them.
To illustrate this concept, consider a function, let's call it function1, that relies on a helper function, function2, to perform a substantial portion of its tasks, as shown in below example.
In this scenario, if the path to func1 is directory/function1.m and function2 is found in the directory directory/private/function2.m, then function2 is only accessible to functions within directory, such as function1.
function y = function1(x)
y = function2(x) + 1;
end
function y = function2(x)
y = 41;
end
| Version | Description |
|---|---|
| 1.0.0 | initial version |