Addpath with user defined string problem
Afficher commentaires plus anciens
Hey everyone,
Tried searching for answer but could not just figure it out. The problem is that matlab functions are on a shared platform. I'm trying to create addpath command that works with every user and the problem is that the path is different on every user. I don't understand why the following command doesn't work:
---------------------------------------------------------------------------------------------------------
username = char(java.lang.System.getProperty('user.name'));
%Returns the unique username that is different on each user and also used in the path, something like xxx123,also tried using username = getenv('username');
addpath(genpath((sprintf('C:\\Users\\%username\\xxxxx\\xxx\\xx',username))))
%This doesn't work, tried without genpath and with couple of different methods like using (['C:... but nothing worked.
%fprintf returns a weird 700 characters long string, something like 'C:\\Users\\50sername\\xxxxx\\xxx\\xx' 'C:\\Users\\79sername\\xxxxx\\xxx\\xx'...
---------------------------------------------------------------------------------------------------------
All help appreciated to how to use addpath and genpath with user defined variable!
Thank you!
2 commentaires
Well, I don't know about the whole thing and it's first day back at work after 2 weeks so I am maybe still slow on the uptake, but at the very least:
%username
is not a valid format specifier for sprintf. You should just be using %s if you want to substitute in a string which is what you seem to want to do. If you are trying to access an environment variable or something like that then certainly that wouldn't work in sprintf like that.
%u
expects an unsigned integer to be substituted in and the remainder 'sername' will just be inserted as a static string as you see in your output.
Valkmi
le 3 Jan 2017
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Search Path dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!