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');
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值