I would like to access functions that are inside a private folder with matlab. it would be very nice to know how to add a path for the private folders?
-
Of course, as several have mentioned, you can copy the contents to another folder. But this results in duplicate files. This issue comes up for me in developing an maintaining toolboxes with private (non-user callable) functions. I too would like a means of adding and calling such functions to simplify development (I've ended up editing the wrong copy of a function too many times). – horchler Oct 30 '13 at 13:17
-
What are you trying to accomplish exactly? If you just want to use those private functions it should be sufficient to call them from your own functions. – Dennis Jaheruddin Oct 30 '13 at 14:15
-
I'm kind of confused. I somehow assumed that we're talking about "builtin" private functions, which might do something useful but are usually not callable from the outside. To me that would imply that neither of the two functions (original and copy) are modified - there are just two indentical versions. If you are the developer of those private functions yourself, then why make them private in the first place, if you want to call them from a non-private context? – sebastian Oct 30 '13 at 16:16
-
I m not the developer and just have been trying to test a library of function, which seems not working due to this issue.. – sophie Nov 05 '13 at 10:19
-
Assuming the library has been built properly, than access to private methods from the outside most certainly is not what you need. But that might rather be a question for the actual developer(s) of the library... – sebastian Nov 05 '13 at 14:02
5 Answers
I don't think there's a way to get around matlab's path
internals that prevent you from adding "private" folders.
If you really need access to a private function from somewhere within the matlab-installation, you are of course free to copy that private function (or the full directory) to some other place, so that you can add it to your path.

- 9,526
- 26
- 54
-
-
So you should check that the path `'../private'` indeed exists. Since you're using a relative path, check that you're issuing the command from the correct directory. However, once you'll get this one issue resolved, you'll certainly come across the error that "private" directories are not allowed on the path. – sebastian Nov 05 '13 at 13:57
I think the best practice would be to move the function out of the private directory (either by copying it, or by just moving it up one directory.)

- 1,271
- 1
- 10
- 29
-
Agree that having 1 version is better than 2, but not sure if this will still help if you update matlab. – Dennis Jaheruddin Oct 30 '13 at 14:14
-
this does not work... I dont know but I never experienced such thing before... wondering whether it is the update of the R2013a version?? – sophie Nov 05 '13 at 10:13
As it seems that adding the folder to the path is not possible, you can consider an alternative.
Rather than copying the function (which will give you 2 versions to maintain), you should be able to create/find a function that calls the private function that you need.
Now, if your underlying function gets updated you are still ok. (Except when the input format changes, but then you have bigger problems to worry about).

- 21,208
- 8
- 66
- 122
-
the issue I have is that these functions that are inside the private folder are called from functions yet written (and as part as a type of toolbox), hence I cannot go and update each function... – sophie Nov 05 '13 at 10:16
-
@sophie If you are worried about functions I don't understand the problem. Your functions should already be able to access the private functions as private should mean that you cannot run them from the command line. Maybe you need to make sure that the private directory is in a directory that is on the path. – Dennis Jaheruddin Nov 05 '13 at 11:07
-
@ Dennis J. - 'Maybe you need to make sure that the private directory is in a directory that is on the path' that sounds logical to me to check that out - I would like to know how do you do that? – sophie Nov 10 '13 at 06:44
-
@sophie the simplest solution would be to add the containing directory to the path and see whether it helps. Adding a directory can be done with `addpath` – Dennis Jaheruddin Nov 10 '13 at 13:51
I've found the following to be useful for development, e.g. debugging private functions.
cd private
addpath ..
I can use the private functions because they are in my working directory, but I can also call the user-visible functions in the toolbox.

- 1,372
- 1
- 11
- 19
My suggestion if you need to access private function cubicmx.mex stored in
C:\MATLAB\R2011a\toolbox\matlab\polyfun\private
is to create a one line function cubicmx_drv.m in the parent directory
C:\MATLAB\R2011a\toolbox\matlab\polyfun
with a single statement calling the mex one.
In such example, it will read as:
function zi = cubicmx_drv(x,y,z,xi,yi,tri,t)
zi = cubicmx(x,y,z,xi,yi,tri,t);
You just need to remember to re-create again if you change computer or working environment. In addition, you can even re-install it from your own code, with a block like
try
zi=cubicmx(x,y,z,xi,yi,tri,t);
catch
%create (or copy your local version) cubicmx_drv.m to the proper path
error(['Exit and restart matlab to solve this problem'])
end
This automatic solution will work after relaunching matlab.

- 2,199
- 4
- 23
- 44