What I have:
I have a matlab script called myscript.m
which uses the p-coded helper functions fcn_A.p
and fcn_B.p
(which I wrote and have the source code for).
What I want:
I'd like to distribute those to others as a single unit such that:
- The main script can be run through
>> myscript
- The helper functions can accessed outside of the main script - but still be protected.
>> myscript
runs a script - not a function. I.e. variables it defines are set in the matlab base environment- Everything is distributed as one directory or a single file.
As far as possible, I'd also like to avoid protecting myscript
. That way, it can be used as an example of how to use fcn_A
and fcn_B
.
Edit: Optimally, I'd like a file or folder that you just move into your path or working directory and then it all works, without even changing the path.
What I tried:
Putting everything into the same script file doesn't fulfill the second requirement.
Making it a class (either through a classdef
file or a @myscript
directory) doesn't fulfill the third requirement.
Making it a package (using a +myscript
directory) doesn't fulfill the first requirement.
What I believe I need
I believe this could be solved if there was a way to define a 'default' function of a package. Kind of like how the contents of +mypackage/Contents.m
is displayed when you type help mypackage
.
Is there a way to do this?