Calling specific .wav files in nested subfolders

조회 수: 2(최근 30일)
Brian Nguyen
Brian Nguyen 2021년 9월 16일
답변: Geoff Hayes 2021년 9월 16일
Hello,
I have a specific order of .wav files that I want to call and they are nested in many subfolders. An example of the directory the directory will be below.
Stimuli (root)->CC->Processed sentences->EAS-> "#.wav"
->Vocod-> "#.wav"
SO->Processed sentences ->EAS-> "#.wav"
->Vocod-> "#.wav"
SS->Processed sentences ->EAS-> "#.wav"
->Vocod-> "#.wav"
Currently I have a function to generate the exact order of .wav files; it is a matrix with the file number, values for CC vs SO, and values for EAS vs Vocod. However, I am having a hard time trying to find an effecient way to navigate the subfolders and directory to call on the specific .wav file. My current idea is to create a very long for loop/decision tree that will utilize the cd function to go into the subfolder I need and back to the root.
Let me know if theres a better way to handle the directories and subfolders. Thanks!

답변(1개)

Geoff Hayes
Geoff Hayes 2021년 9월 16일
Brian - if you know the path to the file that you want to read, then include that path along with the filename in the code to read the wav file. So you will want to "build" the path name given the data in your matrix. I don't know how your data is stored, but if one row of it is something like
data = {'12' 'CC' 'EAS'}
then you could do
filename = fullfile(pwd, data{2}, 'Processed Sentences', data{3}, [data{1} '.wav'])
which (on my desktop) initializes the filename variable as
filename =
'/Users/ghayes/Documents/MATLAB/CC/Processed Sentences/EAS/12.wav'
I'm assuming that the current directory in your MATLAB environment corresponds to the root of your wav file folder. If not, then you can replace the pwd with something else.

Community Treasure Hunt

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

Start Hunting!

Translated by