read multiple wav files in matlab

折月煮酒 提交于 2019-12-02 16:48:20

问题


I want read multiple wav files one by one in one folder. I wrote this way, but it gives "Invalid Wave File. Reason: Cannot open file." error. But when i change t to number, it works.

for t=1:10
    myFile=['path\','t.wav'];
    [ speech, fs] = wavread( myFile);
end

回答1:


You need to convert the variable t to a string. You were asking to open the file 'path\t.wav', which presumably doesn't exist. Since the variable t is an integer, you can use int2str to convert it to a string:

myFile = ['path\' int2str(t) '.wav'];

Only strings can be concatenated with other strings. Of course if you have fewer than 10 files, then you'll have another problem...




回答2:


you can use the special print f command: sprintf(); to assign myFile this string.

myFile = sprintf('path\%d.wav',t);

sprintf works in MATLAB just like it does in the C environment.



来源:https://stackoverflow.com/questions/16906960/read-multiple-wav-files-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!