MATLAB audioread - 从单元格中的struct调用一个.wav文件时出现问题

问题描述 投票:0回答:1

enter image description here

data_structure是(长度(num_sounds)行x 3列单元格的单元格

  • 每行对应不同的声音
  • 第一列=目录名称
  • 第二列= .wav文件的文件结构
  • 第三列=格式数据 qazxsw poi qazxsw poi

问题在于此

for i=1:num_sounds;

我意识到问题是我同时在同一个文件夹中调用所有'.wav'文件而不是一次调用每个文件

我试过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

但那没用。

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

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

matlab struct syntax wav
1个回答
2
投票

在线

name

表达式enter image description here将同时提供所有文件名(在您的示例中为47)作为函数[y Fs] = audioread((data_structure{i,2}.name)); %%problem here 的输入参数,因此出现错误消息。

如果要单独访问每个data_structure{i,2}.name文件,则需要在audioread返回的结构中对它们进行索引,即

.wav
© www.soinside.com 2019 - 2024. All rights reserved.