Processing the files in a directory hierarchy can be accomplished through the use of recursive functions. The general format is:
1) Call the recursive function with the name of a directory.
2) Use the DIR function to obtain a listing of the directory.
3) Loop through the entries in the listing.
4) If an entry is a directory, then call the function recursively, passing the subdirectory's name as the directory to process.
5) If an entry is not a directory, then process the file.
Please find an example file in the MATLAB Central submission SUBDIR:
Note that MathWorks does not guarantee or warrant the use or content of these submissions. Any questions, issues, or complaints should be directed to the contributing author.