## How can I hide a script so that it is not callable any more?

Asked by Daniel Hornung

### Daniel Hornung (view profile)

on 5 Feb 2013
Accepted Answer by Jan Simon

### Jan Simon (view profile)

What I want to do:

To have my most used scripts and functions well organized, I put them into different folders, which I then add to my path using a small script which just takes the folder name. Now I also want to give these module-like folders the possibility to do some initialization procedures. This is done by the path-adding script, which also looks for an ''init.m'' file and runs it with ''run(/path/to/folder/init.m)'.

Now I would like to hide that ''init.m'', so that it doesn't clutter my global namespace and possibly other init scripts. Still I need everything else in this folder. I tried simply naming it ''__init__.m'' (guess where I got this organization idea from...), a very unusual name which would probably not be used accidentally in other places; but starting script names with an underscore seems to be illegal in Matlab.

## Products

### Jan Simon (view profile)

Answer by Jan Simon

### Jan Simon (view profile)

on 5 Feb 2013

Any method, which hides the function, make it unaccessible - according to the definition of "hiding".

Another strategy is to collect the init files with individual names in a separate folder:

```MFiles\inits\init_MyToolboxA.m
MFiles\inits\init_MyToolboxB.m
MFiles\MyToolboxA\
MFiles\MyToolboxB\
```

Now only MFiles\inits\ is stored persistently in the path and Running init_MyToolboxA adds the folders of the toolbox "A" and performs any individual initializations.

On the other hand having an init.m in each folder is not too bad. E.g. Matlab stores a "Contents.m" in each folder also without causing troubles or confusions. You find multiple "prefspanel.m" also.

### Sean de Wolski (view profile)

Answer by Sean de Wolski

### Sean de Wolski (view profile)

on 5 Feb 2013
Edited by Sean de Wolski

### Sean de Wolski (view profile)

on 5 Feb 2013

I would recommed using packages in exactly the same way. Here is the doc for packages:

http://www.mathworks.com/help/releases/R2012b/matlab/matlab_oop/scoping-classes-with-packages.html

Basically you could have packages for whatever you want:

Example files:

```+StuffIUse\+Utilities\etc.m
+OldStuff\+Utilities\etc.m
```

Now to use the typical stuff:

```x = StuffIUse.Utilities.etc
```

But let's say you wanted to use old stuff:

```x = OldStuff.Utilities.etc
```

If both +StuffIUse and +OldStuff are on the path; you'll have access to all of the sub-packages without having to do any path manipulation or calling run() !!!

Daniel Hornung

### Daniel Hornung (view profile)

on 5 Feb 2013

Thanks, for the moment Jan's solution is closer to what I need, but I think I should switch to packages on the long run.

#### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today