MATLAB Answers

How to run a function which is not on the path?

조회 수: 50(최근 30일)
K E
K E 8 Oct 2012
I would like to run a function which is not on MATLAB's path. Formerly I did this with evalf, but once I upgraded to R2012b, the program fails here:
str2func(funcNam)
Warning: The input to STR2FUNC
"S:/source/matlab/utils/graphics/distinguishable_colors" is not a
valid function name. This will generate an error in a future release.
So, is there another way to run a function if the function is not on the path? While it is possible to run a script which is not on the path, that doesn't help because I need the function's outputs. I don't want to add the directory to my path because it has so many directories that it is causing issues with performance. I suppose I could just change to the function's directory, run it, and change back to my initial directory. But perhaps there is a better solution.

채택된 답변

Walter Roberson
Walter Roberson 8 Oct 2012
Changing directories is your only option.
You can edit the code for run. There is no reason that I could see that run() could not be adapted to return values.
Do note, though, that if you are relying on anything in the function being called relies on a function found in the current directory as of the time you call the function, then you are going to have problems; you would also have problems if the new directory "shadows" functions in a different way than the other directories do.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by