how to change from one directory to another

10 views (last 30 days)
Hello, I have two folders in a parent folder. One folder contains jpg images while the other contains mat files. I then create 3 separate folders within which I want to process the data in the two original folders and store them in the 3 created folders using for loops for each of the 3 folders. After processing and storing data in the first folder, how can I come out of that folder and access the second folder to process and store data before going out of it and accessing the third folder and doing the same. Thanks for any assistance.
  1 Comment
Stephen23
Stephen23 on 3 Dec 2015
Rather than changing directories, you should pass a path argument to your functions. This is much more reliable and robust, as the link in Image Analyst's Answer's explains.

Sign in to comment.

Accepted Answer

valdal
valdal on 1 Dec 2015
Hello Ogheneochuko,
You can use the function 'cd' and the double dot to go to the parent directory :
cd ..
or
cd('..')
('..' represent the parent directory while '.' represent the current directory)
If you want to come out of the current folder and access an other folder :
cd ../folder2
or
cd('../folder2')

More Answers (1)

Image Analyst
Image Analyst on 3 Dec 2015
If you want an easier time than the above method you accepted, use genpath(). See may attached demo which goes into every subfolder getting filenames.

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!