matlab 文件批量处理

matlab—批量处理文件和子文件

任务描述
——文件夹speech_commans10中有10个文件,分别是down ,go ,left ,no, off, on ,right,stop, up,yes.10类语音样本
目标:
——将这10类样本都一起放在一个sample中【cell格式】;并且将对应的标签放在label中【cell格式】
注意的问题:
——1、定义cell需要知道cell的大小,比如a = cell(2,1)
——2、A这个变量很重要,这是能够在sample这个元组中存放数据的关键变量。

% load('\dataset\speech_commands10\speech_commands10\down\');
clc;
clear all;

maindir = 'speech_commands10/speech_commands10/'; % 文件夹
file = dir(maindir);
file(1:2) = [];
F = length(file);

sample=cell(23682,1);
label=cell(23682,1);
A=0;
for f =1:F
    filepath = fullfile(maindir,file(f).name,'*.wav'); % only read wav file
    waves = dir(filepath);% all wav file
    L=length(waves); 
  
    for i =1:L              
        wavepath = fullfile(maindir,file(f).name,waves(i).name);  
        [x,fs]=audioread(wavepath);
        
        sample{A+i,1} = x;
        label{A+i,1} = f;
    end 
      A = A+L;
   
end
save('speech_command.mat','sample','label');

你可能感兴趣的:(matlab编程,matlab)