Is it possible to use "userpath" as a normal variable in MATLAB 7.6 (R2008a)?

1 view (last 30 days)
When I execute the following code
userpath(1:end-1)
I receive the following error message:
??? Error: The end operator must be used within an array index
expression.
Also
cd userpath
gives error message:
??? Error using ==> cd
Cannot CD to userpath (Name is nonexistent or not a directory).
I would like userpath to behave like a normal variable which I can index into and also change directories based on userpath.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Dec 2011
This change has been incorporated into the documentation in Release 2011b (R2011b). For previous releases, read below for any additional information:
"userpath" is a reserved function name in MATLAB and is needed to reference the MATLAB path. Creating a variable with a same name shadows the userpath function. Therefore the ability to use userpath as a normal MATLAB variable, and index or cd into it is not available in MATLAB.
To work around this issue, store the result of userpath in a variable and then perform the desired operation on it.
For instance:
a=userpath;
a=a(1:end-1);
cd(a);

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!