How can I use a variable (i.e. a folder path) as the argument for cd function?
114 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pablo Jaramillo Restrepo
el 7 de Feb. de 2016
Comentada: Maria Byrne
el 16 de Jul. de 2020
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\'
0 comentarios
Respuesta aceptada
Walter Roberson
el 7 de Feb. de 2016
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 comentarios
Adam
el 14 de Jun. de 2018
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
el 16 de Jul. de 2020
what worked for me was cd(char(A)) since A was actually a cell even though it looked like a string
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!