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
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...
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