Problem locating function file

I created a function using an existing function in the stats toolbox. In particular, I just made a few tweeks and saved the modification using a different function name. First, I saved it in my working directory and Matlab could not find it (yes I used the same spelling). Then, I saved it in the stats toolbox directory and Matlab did find the function when using the 2007a version but not when using the 2008b or 2009b versions. And yes, I have set the path to this directory and have no problems calling other functions in the toolbox in any of the versions.
Any ideas on why this is happening?

Risposte (2)

Walter Roberson
Walter Roberson il 15 Ott 2011

0 voti

You should never store your own function in one of the toolbox directories, in any version.
It is not a good practice to name your own function the same as an existing MATLAB function: if you do that and your own function is earlier on the path than the existing function, then even Mathwork's own routines will call the one you created, which can lead to obscure problems.
You should also explore the "rehash" command.

1 Commento

Mike
Mike il 16 Ott 2011
Thanks for the reply. I did not name the my function the same as the pre-existing Matlab function though. I also realize that it is not a good idea to save my own functions in the toolboxes, but as I mentioned, Matlab could not find it otherwise, even if I save it in the workspace which seems very strange to me. I

Accedi per commentare.

Jan
Jan il 15 Ott 2011

0 voti

The toolbox folders are included in the path in 'freezed' mode (see: help addpath), such that new files in these folders are recognized after rehash toolboxreset only.
Therefore it is strongly suggested not to write into the toolbox paths. Create a user-defined folder and include it in the path. Crae for a function name, which does not conflict with names of a toolbox function.

Categorie

Tag

Richiesto:

il 15 Ott 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by