From: sunder_79 on 27 Sep 2006 20:14 Hi, I have a set of large flat files that I'd like to read in one after the other in a loop. I'm looking for specific columns of data from each file. However the number of columns varies from file to file (and there are lots of them and so it's very timeconsuming to specify the format for each file). Is there a way to read a file in using textread or textscan without specifying the number/format of the columns. If I can do this, then I'd be able to find the appropriate columns that I need by matching the headers. Thanks a lot for your help! Sunder
From: Fort on 28 Sep 2006 02:44 Sunder, You could just read in the first line (or the whole header) to determine the number of columns using an fscanf() and then close the file. Compute the number of columns, generate an appropriate format string and read it in using textread/textscan or even just fscanf. --Fort sunder_79(a)yahoo.com wrote: > Hi, > > I have a set of large flat files that I'd like to read in one after the > other in a loop. I'm looking for specific columns of data from each > file. However the number of columns varies from file to file (and there > are lots of them and so it's very timeconsuming to specify the format > for each file). Is there a way to read a file in using textread or > textscan without specifying the number/format of the columns. If I can > do this, then I'd be able to find the appropriate columns that I need > by matching the headers. > > Thanks a lot for your help! > Sunder
From: sunder_79 on 28 Sep 2006 13:33 Hi Fort, thanks for the response. I haven't used fscanf before but from the documentation it seemed like I would need to specify the format of the columns - which is what I'm trying to avoid doing. Is there a way to read in the file without specifying the format or number of columns. Or having all the columns default to the same format? Thanks, Sunder Fort wrote: > Sunder, > > You could just read in the first line (or the whole header) to > determine the number of columns using an fscanf() and then close the > file. Compute the number of columns, generate an appropriate format > string and read it in using textread/textscan or even just fscanf. > > --Fort > > > sunder_79(a)yahoo.com wrote: > > Hi, > > > > I have a set of large flat files that I'd like to read in one after the > > other in a loop. I'm looking for specific columns of data from each > > file. However the number of columns varies from file to file (and there > > are lots of them and so it's very timeconsuming to specify the format > > for each file). Is there a way to read a file in using textread or > > textscan without specifying the number/format of the columns. If I can > > do this, then I'd be able to find the appropriate columns that I need > > by matching the headers. > > > > Thanks a lot for your help! > > Sunder
From: Christopher Brown on 28 Sep 2006 13:56 Try autodataread.m, works great for me: <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3399> sunder_79 wrote: > > > Hi Fort, > > thanks for the response. I haven't used fscanf before but from the > documentation it seemed like I would need to specify the format of > the > columns - which is what I'm trying to avoid doing. Is there a way > to > read in the file without specifying the format or number of > columns. Or > having all the columns default to the same format? > > Thanks, > Sunder > > Fort wrote: >> Sunder, >> >> You could just read in the first line (or the whole header) to >> determine the number of columns using an fscanf() and then close > the >> file. Compute the number of columns, generate an appropriate > format >> string and read it in using textread/textscan or even just > fscanf. >> >> --Fort >> >> >> sunder_79(a)yahoo.com wrote: >> > Hi, >> > >> > I have a set of large flat files that I'd like to read in one > after the >> > other in a loop. I'm looking for specific columns of data from > each >> > file. However the number of columns varies from file to file > (and there >> > are lots of them and so it's very timeconsuming to specify the > format >> > for each file). Is there a way to read a file in using textread > or >> > textscan without specifying the number/format of the columns. > If I can >> > do this, then I'd be able to find the appropriate columns that > I need >> > by matching the headers. >> > >> > Thanks a lot for your help! >> > Sunder > >
From: Jos on 28 Sep 2006 14:23
sunder_79 wrote: > > > Hi, > > I have a set of large flat files that I'd like to read in one after > the > other in a loop. I'm looking for specific columns of data from each > file. However the number of columns varies from file to file (and > there > are lots of them and so it's very timeconsuming to specify the > format > for each file). Is there a way to read a file in using textread or > textscan without specifying the number/format of the columns. If I > can > do this, then I'd be able to find the appropriate columns that I > need > by matching the headers. > > Thanks a lot for your help! > Sunder > > If a file contains only numbers try using "load" A = load('myfile.txt') ; hth Jos |