Path: news.mathworks.com!not-for-mail
From: "David Starkweather" <starkdg@comcast.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Wavread loop: Variable filename
Date: Sat, 6 Dec 2008 21:48:02 +0000 (UTC)
Organization: n/a
Lines: 69
Message-ID: <gherui$69v$1@fred.mathworks.com>
References: <gat6nh$c36$1@fred.mathworks.com> <gata66$d30$1@fred.mathworks.com> <gatahf$fsi$1@fred.mathworks.com> <MPG.233d5e8a1c997d179898d1@news.mathworks.com>
Reply-To: "David Starkweather" <starkdg@comcast.net>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228600082 6463 172.30.248.38 (6 Dec 2008 21:48:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 6 Dec 2008 21:48:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1532007
Xref: news.mathworks.com comp.soft-sys.matlab:505399


Loren Shure <loren@mathworks.com> wrote in message <MPG.233d5e8a1c997d179898d1@news.mathworks.com>...
> In article <gatahf$fsi$1@fred.mathworks.com>, Firstname.Lastname@Where-
> I-Work.com says...
> > "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message <gata66$d30$1@fred.mathworks.com>...
> > > "Koos Spee" <bmx_360@hotmail.com> wrote in message <gat6nh$c36$1@fred.mathworks.com>...
> > > > Hello,
> > > > 
> > > > I have a set of (wav)files e.g.
> > > > 
> > > > file01.wav, file02.wav, file03.wav etc.
> > > > 
> > > > Now, I want to get load these files into Matlab with a loop and storing them into load01, load02, load03 etc
> > > > 
> > > > However I am not able to give them the correct filename. I tried for example:
> > > > 
> > > > for i=1:3
> > > >     StrI=int2str(i);
> > > >     WavName='file';
> > > >     WavStored='load';
> > > >     temp=strcat(WavName, StrI);
> > > >     strcat(WavStored, StrI)=wavread(temp);
> > > > end
> > > > 
> > > > Also looked into dir('*wav'), but that leads to the same problem
> > > 
> > > What about something different like this (untested):
> > > 
> > > files=dir('*.wav');
> > > for file = files
> > >   file.data=wavread(file.name);
> > > end
> > 
> > Should have tested!
> > 
> > files=dir('*.wav');
> >   for n=1:length(files);
> >   files(n).data=wavread(files(n).name);
> > end
> > 
> > 
> > 
> 
> This is likely to cause issues as files gets redefined in a loop with a 
> control variable named files.  Please follow the suggestions from the 
> FAQ instead!  Or how about this:
> 
> 
> files=dir('*.wav');
> for n=1:length(files);
>     basename = files(n).name;
>     basename(end-3:end) = '';
>     data.(basename)=wavread(files(n).name);
> end
> 
> 
> >> data
> data = 
>       gong: [42028x1 double]
>     handel: [73113x1 double]
> 
> 
> 
> -- 
> Loren
> http://blogs.mathworks.com/loren

Even with these techniques, I get "out of memory error".  I am trying to read in all wav files in a given directory.  So far, it will only work for 2 or 3 files and then the error message.  Does anyone know if this has been a problem with earlier versions of matlab ?  (I am using Matlab 6.5 R13)  Even 'clear' and 'pack after each loop iteration doesnt help.

dgs.