I have a private function that I need to call from a MATLAB script (not a function).
Apparently, you can only access a private function from another function, but not from a script. You can read about this here.
In order to overcome this problem I simply included a function header with no input and output arguments.
Like this:
function myFunction()
% original script
% call private function here
end
This solved the problem, but why this small change makes such a big difference?
The page you linked already contains the relevant information:
Private functions are useful when you want to limit the scope of a function. You designate a function as private by storing it in a subfolder with the name private. Then, the function is available only to functions in the folder immediately above the private subfolder, or to scripts called by the functions that reside in the parent folder.
A script does not have it's own scope/workspace , it inherits the scope/workspace of the caller. In your case (assuming you call it directly from the console) it is the base workspace where the function is not visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With