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?

답변 (2개)

Walter Roberson
Walter Roberson 2011년 10월 15일

0 개 추천

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

Mike
Mike 2011년 10월 16일
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

댓글을 달려면 로그인하십시오.

Jan
Jan 2011년 10월 15일

0 개 추천

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.

카테고리

도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2011년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by