MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Import[file,"Table"] ????

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65001] Re: [mg64992] Import[file,"Table"] ????
  • From: ggroup at sarj.ca
  • Date: Sat, 11 Mar 2006 05:15:37 -0500 (EST)
  • References: <duh2s0$5qg$1@smc.vnet.net> <dujsaq$963$1@smc.vnet.net> <200603080600.BAA03158@smc.vnet.net> <200603101015.FAA22051@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I've seen this too, though it only happened on some files.  I never could find 
a pattern for when this would happen.  I was generating text data files from 
multiple measurement devices (all working identically), and some (few and far 
between) wouldn't import properly.  There were *no* clues in the text file as 
to why this was happening, even at a binary level.

The only trick that worked for my case was to recreate the text file with the 
same data.  An effective way was to import the file as lines so that I got 
each row as a string.  I then used ImportString to convert the individual 
strings into data.  Finally, I used to Export the result as a Table so that I 
would create a file that Import could handle more easily.  I could then use 
this new file in my main notebook with no problem.  I don't have access to 
those notebooks anymore, but essentially the psuedo-code was something like:

strdata = Import["filename", "Lines"];
data = ImportString[ #, "Table" ]& /@ strdata;
Export["newfilename", data, "Table"]

Note that this is a very slow method, but it was the only one that worked and 
that my data would allow me to use.  

Now you may be able to avoid some of that work if your files are very clean.  
In my files, there would be marker lines and the occassional corrupt line that 
would change my data types and number of elements on a line.  This meant that 
I couldn't use something like ReadList, but perhaps that would be an easier 
solution for you.

Good luck!


On Fri, 10 Mar 2006 05:15:26 -0500 (EST), Maurits Haverkort wrote
> Dear All
> 
> I have a file consisting of a table of numbers, where the coloms are
> seperated by spaces and the rows by newlines.
> 
> Lets say I have col colums and row rows in my file.
> 
> If I use the commond Import[file,"Table"] I get in mathematica a list 
> of lenght two. The first entety is a list of length col, the second of 
> lenght
> (row-1)*col.
> 
> I would like to get a matrix of dimensions [col,row], how can I correct
> this.
> 
> Thanks in advace,
> Maurits Haverkort





  • Prev by Date: Re: optimization nested in root-finding
  • Next by Date: Re: first variation of the functional
  • Previous by thread: Import[file,"Table"] ????
  • Next by thread: FindRoot Secant Method