Thread Subject: Reading from a .txt file

Subject: Reading from a .txt file

From: Zain Zahid

Date: 28 Jan, 2012 10:19:09

Message: 1 of 4

Hello,

I have a text file (refFileList.txt) which has the names of some .wav files (M01W01R1.wav etc) that i want to read one after the other in Matlab.

I have tried uiimport, uigetfile, importdata etc but it doesnt serve the purpose.

Please suggest a way to read the multiple .wav files from a .txt document in matlab.

Thank you.

Subject: Reading from a .txt file

From: pietro

Date: 28 Jan, 2012 10:32:10

Message: 2 of 4

"Zain Zahid" wrote in message <jg0i2t$n25$1@newscl01ah.mathworks.com>...
> Hello,
>
> I have a text file (refFileList.txt) which has the names of some .wav files (M01W01R1.wav etc) that i want to read one after the other in Matlab.
>
> I have tried uiimport, uigetfile, importdata etc but it doesnt serve the purpose.
>
> Please suggest a way to read the multiple .wav files from a .txt document in matlab.
>
> Thank you.

Try txt2mat. You can find this routine in the file exchange, it works perfectly!

Subject: Reading from a .txt file

From: Zain Zahid

Date: 28 Jan, 2012 11:28:10

Message: 3 of 4

@pietro

Thank you but,

Unfortunately it doesn't help me. I am working on isolated speech recognition using matlab.

The algorithm i'm trying to implement is:

for (all .wav files in testFileList.txt)
  read the next .wav file

where testFileList.txt contains the names of five .wav files.

Subject: Reading from a .txt file

From: dpb

Date: 28 Jan, 2012 13:50:39

Message: 4 of 4

On 1/28/2012 5:28 AM, Zain Zahid wrote:
...

> The algorithm i'm trying to implement is:
>
> for (all .wav files in testFileList.txt)
> read the next .wav file
>
> where testFileList.txt contains the names of five .wav files.

I'd suggest you consider using dir() instead (presuming you have a
naming convention that makes selecting the desired files feasible w/ a
wildcard or other way) instead...

d=dir('*.wav');
for idx=1:length(d)
   fid=fopen(d{idx).name,'r');
   % do whatever...
   fid=fclose(fid); % done w/ this one
end

If really want to use the alternate way,

d=textread('testFileList.txt','%s');
for idx=1:length(d)
   fid=fopen(d{idx},'r');
   % do whatever...
   fid=fclose(fid); % done w/ this one
end

NB in the latter d is a cell array, so need the curly braces to
dereference. You may also prefer to use the newer textscan instead of
the deprecated textread (which is all available is in my older version)

--

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
wav Zain Zahid 28 Jan, 2012 05:19:13
txt Zain Zahid 28 Jan, 2012 05:19:13
speech recognition Zain Zahid 28 Jan, 2012 05:19:13
reference template Zain Zahid 28 Jan, 2012 05:19:13
importdata Zain Zahid 28 Jan, 2012 05:19:13
rssFeed for this Thread

Contact us at files@mathworks.com