0

enter image description here

data_structure is a cell of (length(num_sounds) row x 3 column cell

  • each row corresponds to a different sound
  • first column = directory name
  • second column = files struct for .wav files
  • third column = formant data

    for i=1:num_sounds; cd(char(sound_dirs{i})); %open a directory wav_list=dir('*.wav'); %get all the .wav files in the folder data_structure{i,2}=wav_list; % fills second column with struct the length of the .wav files. data_structure{i,1}=words{i}; end

problem lies here

 for i=1:num_sounds;
        num_wavs=length(data_structure{i,2}); 
        for i=1:num_wavs;
            [y Fs]= audioread((data_structure{i,2}.name)); %%problem here

I realize the issue is that I'm calling all the '.wav' files in the same folder at the same time and not taking each one at a time

I tried data_structure{1,2}.name(40); % the first folder has 47 .wav files

but that didn't work.

name <-- holds all the the names of the .wav files.

enter image description here

9
  • 1
    data_structure{1,2}(40).name Commented Apr 14, 2019 at 13:51
  • I tried this for i=1:num_sounds; i_num_wavs=length(data_structure{i,2}); for j=1:i_num_wavs; [y Fs]= audioread(data_structure{i,2}(j).name); end end I used @CrisLuengo's suggestion, and it worked in the command window but it still won't run in the script. Commented Apr 14, 2019 at 17:00
  • error Error using audioread (line 90) The filename specified was not found in the MATLAB path. Error in celldir (line 37) [y Fs]= audioread(data_structure{i,2}(j).name); Commented Apr 14, 2019 at 17:01
  • 1
    Don’t use cd. You end up in the last directory, so all the files you read are from there. Use fullfile(directory_name,file_name) both when listing the directory contents (where file_name is *.wav) and when reading the file. Commented Apr 14, 2019 at 19:29
  • 1
    I started writing an answer to your new question, but that's been deleted. Is this clear now? I'm suggesting wav_list=dir(fullfile(char(sound_dirs{i}),'*.wav')); and audioread(fullfile(char(sound_dirs{i}),data_structure{i,2}.name)). Commented Apr 15, 2019 at 17:10

1 Answer 1

2

In the line

[y Fs] = audioread((data_structure{i,2}.name)); %%problem here

the expression data_structure{i,2}.name will feed the all the file names (47 in your example) at once as input arguments to the function audioread, hence the error message.

If you want to access each .wav file individually, you need to index them within the struct returned from dir, i.e.,

for i=1:num_sounds;
    these_files = data_structure{i,2};
    for i=1:length(these_files)
        [y Fs] = audioread(these_files(i).name));
        % Do whatever needs to be done with y, Fs
    end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.