Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3427
| From | "McHale, Paul" <Paul.McHale@excelitas.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Reading Data Table |
| Date | 2011-07-01 00:44 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <iuj58m$nof$1@smc.vnet.net> (permalink) |
| References | <201106301030.GAA15503@smc.vnet.net> |
One quick way to do it is to read it in as a string and then use ImportString [] to sort it out.
TestA.Txt:
1 2 3
4 5 6
In= mList=Import["c:\\testa.txt"];
In= mList=ImportString[mList,"Table"]
Out= {{1,2,3},{4,5,6}}
OR
In= ReadList["C:\\testa.txt", Number, RecordLists -> True, WordSeparators-> {" ", "\[Backslash]t"}, RecordSeparators -> {"\r\n", "\n", "\r"}]
Out= {{1,2,3},{4,5,6}}
Note: Don't leave Number specifier out! Also, here is the URL in the help system that I used (if it helps):
tutorial/ReadingTextualData
Type that into the search box in the help system.
Paul McHale | Electrical Engineer, Energetics Systems | Excelitas Technologies Corp.
Phone: +1 937.865.3004 | Fax: +1 937.865.5170 | Mobile: +1 937.371.2828
1100 Vanguard Blvd, Miamisburg, Ohio 45342-0312 USA
Paul.McHale@Excelitas.com
www.excelitas.com
Please consider the environment before printing this e-mail.
This email message and any attachments are confidential and proprietary to Excelitas Technologies Corp. If you are not the intended recipient of this message, please inform the sender by replying to this email or sending a message to the sender and destroy the message and any attachments.
Thank you
-----Original Message-----
From: fractal11 [mailto:trchan@mit.edu]
Sent: Thursday, June 30, 2011 6:31 AM
Subject: Reading Data Table
Is there a way to read a file with a user specified word separator and record separator, such that the result is a list of lists of words?
For example, a file containing "1 2 3\n4 5 6" would become {{1,2,3}, {4,5,6}}.
Import does almost exactly what I want, although I can't figure out how to change the word and record separators.
In particular, I have a file where word separators are tab characters, but the data themselves have spaces. Therefore, Mathematica's default word separator of whitespace does not work.
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Reading Data Table "McHale, Paul" <Paul.McHale@excelitas.com> - 2011-07-01 00:44 +0000
csiph-web