I have a folder specified by the path D:\BTP\0 (1)\0 . This contains wave file ranging from 0 to 59 and I need to read each of them using the command
for m=0:59
filename = sprintf('%d.wav',m);
[s,fs] = audioread(filename);
end
I need to specify file name inside sprintf command. How do I do so?

 채택된 답변

Domanic
Domanic 2018년 1월 28일
편집: Domanic 2018년 1월 28일

1 개 추천

You can do this through string concatenation:
mypath = 'D:\BTP\0 (1)\';
for m=0:59
filename = [mypath num2str(m) '.wav'];
[s,fs] = audioread(filename);
end
If it needs to be inside sprintf, you can use:
mypath = 'D:\\BTP\\0 (1)\\';
filename = sprintf([mypath '%d.wav'],m);
where the double slash, \\, generates the single \ in this context.

댓글 수: 4

sangeet sagar
sangeet sagar 2018년 1월 28일
Thank You man. Got it done.
With sprintf:
mypath = 'D:\BTP\0 (1)\';
filename = sprintf('%s%d.wav', mypath, m);
However I recommend instead
mypath = fullfile('D:', 'BTP', '0 (1)');
filename = fullfile(mypath, sprintf('%d.wav', m));
sangeet sagar
sangeet sagar 2018년 1월 28일
I also wanted to ask one more: I have wave files with names like:
00 01 02 03 04 .... and so on till 59. How do I read them using sprintf? The first digit of the filename specifies speaker id and the second digit specifies utterence id .
filename = fullfile(mypath, sprintf('%02d.wav', m));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Movie에 대해 자세히 알아보기

질문:

2018년 1월 28일

댓글:

2018년 1월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by