Question

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
Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top