Conteúdo do Curso
Matlab Basics
Matlab Basics
Recursive Programming
Recursive programming, or having a program call itself, is a fundamental aspect of programming that serves a unique role. Here you'll learn how to write a recursive program that searches through a tree of subfolders and identifies those containing files of interest. Having this tool in hand allows you to automate your analyses and graphing across libraries of data files at the push of a button.
Task
Download the program Identify_Relevant_Subfolders_N_C
.
-
Modify the variable
number_of_hidden_system_files
based on your operating system, as shown in the video:- Create a blank folder on your desktop;
- Use the
dir
function to retrieve its directory (see Section 4, Chapter 5). Assign a variable to collect the output; - Look at how many rows are in the returned structure, and change
number_of_hidden_system_files
to this number.
-
Create a random tree of folders, some containing Excel files, some not, and run
Identify_Relevant_Subfolders_N_C
on the parent folders. -
Check to see if it identified all the subfolders that you put Excel files in. In your future programming, if you need to run analyses or graphing on files contained within a directory of folders, you can:
- Run
Identify_Relevant_Subfolders_N_C
(perhaps changing the extension of the file types you're looking for) on the parent folder to get a list of all the subfolders of interest; - Create a module to for loop over that list of subfolders, using the
dir
function to pull each folder's contents and perhaps some if statements to focus on certain files, and run your analyses/graphing on each one.
- Run
Obrigado pelo seu feedback!