问题
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?
回答1:
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.
回答2:
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.)
回答3:
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).
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/19680611/how-can-i-add-a-matlab-path-to-a-private-folder