How can I use a variable (i.e. a folder path) as the argument for cd function?

171 次查看(过去 30 天)
Hi! I think this is a syntax-type question:
I want to use cd to change between directories that are stored in a looping variable. What would be the syntax so cd('path'); can be performed, 'path' being :\Users\p_jarami\A\'

采纳的回答

Walter Roberson
Walter Roberson 2016-2-7
projectdir = 'C:\Users\p_jarami\A\';
cd(projectdir)
You should avoid using a variable named "path" as that variable means special things to MATLAB.
  5 个评论
Adam
Adam 2018-6-14
You could try the solution in the answer you are replying to!! You went to the trouble of finding a relevant question and commenting on an answer so why not simply apply the answer?!
cd( A )
It's highly unlikely that using cd and changing directory in a loop is a good idea in most cases, but that is another matter, depending what you are doing. Using full paths to files is generally far better.
Maria Byrne
Maria Byrne 2020-7-16
what worked for me was cd(char(A)) since A was actually a cell even though it looked like a string

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by