MATLAB: Using addpath with a user defined string

addpathuser defined input

I'm trying to use the addpath command in a script but with a user defined folder name which I want to delete at the end of the script. There are several folders in the path, all containing files of the same name (output from a program) but the folder names are different.
Using foldername=input('Enter the folder name:','s')
then
addpath C:\xxx\'foldername'
Doesn't work because addpath doesn't read the string input. Any thoughts?

Best Answer

The single quotes are messed up. Try just passing in the variable (if it's the full path):
addpath(foldername);
Otherwise
folder = sprintf('C:\xxx\%s', foldername);
addpath(folder);
or simply call uigetdir() instead of input , which is probably what you should do.
Related Question