필터 지우기
필터 지우기

How to make for loop ?

조회 수: 2 (최근 30일)
Negar
Negar 2013년 10월 22일
댓글: sixwwwwww 2013년 10월 22일
Hello everyone,
I have a folder (database) containing some wav files , and I want to read each of them to extract some features later. I know how to read each file from the list by wavread, for example the first one would be: [signal,Fs,nbits,opts] = wavread('database/ae/ae_0a01.wav') And the second one: [signal,Fs,nbits,opts] = wavread('database/ae/ae_0a02.wav') and so on. But I can not figure out how to make loop in order to automatically get them loaded one by one. Could anybody help in that case?
Thanks
  댓글 수: 1
Negar
Negar 2013년 10월 22일
Oh, forgot to say that I have the file list as txt file 'all files.txt' ... So my question is how to pick this files one after the other ... Thank you

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

채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 22일
편집: sixwwwwww 2013년 10월 22일
Dear Negar, try this:
for j = 1:length(files)
[signal,Fs,nbits,opts] = wavread(strcat('database/ae/ae_0a0', num2str(j), '.wav'));
end
Or better way is using:
dir
to information about all the files in a particular directory and then read them. See http://www.mathworks.de/de/help/matlab/ref/dir.html
In case you have file names stored in text file you can do as follows:
ID = fopen('filename.txt');
files = textscan(ID, '%s');
fclose(ID)
fileNames = files{:};
for j = 1:length(fileNames)
[signal,Fs,nbits,opts] = wavread(fileNames{j});
end
I hope it helps. Good luck!
  댓글 수: 2
Negar
Negar 2013년 10월 22일
Thank you , but I have a question, in first way,
for j = 1:length(files) [signal,Fs,nbits,opts] = wavread(strcat('database/ae/ae_0a0', num2str(j), '.wav')); end
how to make the file name for file nr.10 and above?
sixwwwwww
sixwwwwww 2013년 10월 22일
In that case you can do like this:
for j = 1:length(files)
if j <10
[signal,Fs,nbits,opts] = wavread(strcat('database/ae/ae_0a0', num2str(j), '.wav'));
else
[signal,Fs,nbits,opts] = wavread(strcat('database/ae/ae_0a', num2str(j), '.wav'));
end
end
Good luck!

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 22일
out=cell(9,4);
for k=1:9
file=sprintf('database/ae/ae_0a0%d.wav')
[signal,Fs,nbits,opts] = wavread(file)
out{k,1}=signal;
out{k,2}=Fs;
out{k,3}=nbits;
out{k,4}=opts;
end

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by