Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: How can I import a file wiht a space as a separator?
Replies: 1   Last Post: Jan 11, 2013 10:23 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
hmichel@cox.net

Posts: 120
Registered: 1/29/05
Re: How can I import a file wiht a space as a separator?
Posted: Jan 11, 2013 10:23 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

David:
In Mathematica version 9
Using examples from the PDF file in the link:
Example 4:
# GHZ S RI R 50.0
!freq RelS11 ImS11 ReS21 ImS21 ReS12 ImS12 ReS22 ImS22
1.0000 0.3926 -0.1211 -0.0003 -0.0021 -0.0003 -0.0021 0.3926 -0.1211
2.0000 0.3517 -0.3054 -0.0096 -0.0298 -0.0096 -0.0298 0.3517 -0.3054
10.000 0.3419 0.3336 -0.0134 0.0379 -0.0134 0.0379 0.3419 0.3336

To import in Mathematica I saved the data to a file

In[10]:= Import["E:\\Stuff\\touchstone4.txt", "Table", "HeaderLines"->2,
"FieldSeparators"->{" ","\t"}]
Out[10]=
{{1.,0.3926,-0.1211,-0.0003,-0.0021,-0.0003,-0.0021,0.3926,-0.1211},{2.,0.35
17,-0.3054,-0.0096,-0.0298,-0.0096,-0.0298,0.3517,-0.3054},{10.,0.3419,0.333
6,-0.0134,0.0379,-0.0134,0.0379,0.3419,0.3336}}

Example 5:
# GHZ S MA R 50
5.00000 0.60 161.24 0.40 -42.20 0.42 -66.58 0.53 -79.34 !row 1
0.40 -42.20 0.60 161.20 0.53 -79.34 0.42 -66.58 !row 2
0.42 -66.58 0.53 -79.34 0.60 161.24 0.40 -42.20 !row 3
0.53 -79.34 0.42 -66.58 0.40 -42.20 0.60 161.24 !row 4
6.00000 0.57 150.37 0.40 -44.34 0.41 -81.24 0.57 -95.77 !row 1
0.40 -44.34 0.57 150.37 0.57 -95.77 0.41 -81.24 !row 2
0.41 -81.24 0.57 -95.77 0.57 150.37 0.40 -44.34 !row 3
0.57 -95.77 0.41 -81.24 0.40 -44.34 0.57 150.37 !row 4
7.00000 0.50 136.69 0.45 -46.41 0.37 -99.09 0.62 -114.19 !row 1
0.45 -46.41 0.50 136.69 0.62 -114.19 0.37 -99.09 !row 2
0.37 -99.09 0.62 -114.19 0.50 136.69 0.45 -46.41 !row 3
0.62 -114.19 0.37 -99.09 0.45 -46.41 0.50 136.69 !row 4

To import in Mathematica I saved the data to a file

In[11]:=
Import["E:\\Stuff\\touchstone5.txt","Table","HeaderLines"->1,"FieldSeparator
s"->{" ","\t","!row"}]
Out[11]=
{{5.,0.6,161.24,0.4,-42.2,0.42,-66.58,0.53,-79.34,1},{0.4,-42.2,0.6,161.2,0.
53,-79.34,0.42,-66.58,2},{0.42,-66.58,0.53,-79.34,0.6,161.24,0.4,-42.2,3},{0
.53,-79.34,0.42,-66.58,0.4,-42.2,0.6,161.24,4},{6.,0.57,150.37,0.4,-44.34,0.
41,-81.24,0.57,-95.77,1},{0.4,-44.34,0.57,150.37,0.57,-95.77,0.41,-81.24,2},
{0.41,-81.24,0.57,-95.77,0.57,150.37,0.4,-44.34,3},{0.57,-95.77,0.41,-81.24,
0.4,-44.34,0.57,150.37,4},{7.,0.5,136.69,0.45,-46.41,0.37,-99.09,0.62,-114.1
9,1},{0.45,-46.41,0.5,136.69,0.62,-114.19,0.37,-99.09,2},{0.37,-99.09,0.62,-
114.19,0.5,136.69,0.45,-46.41,3},{0.62,-114.19,0.37,-99.09,0.45,-46.41,0.5,1
36.69,4}}

You can try "Table" with the Import options tweaked to your format.

Hans

-----Original Message-----
From: David Kirkby [mailto:drkirkby@gmail.com]
Sent: Thursday, January 10, 2013 8:42 PM
Subject: How can I import a file wiht a space as a separator?

You might see from my previous post I'm looking for a function to read a
Touchsone file format, which is defined by this "draft" standard,

http://vhdl.org/ibis/connector/touchstone_spec11.pdf

which has been draft for 30 years, but is still used as the standard. The
main point is a header (which I can skip), but then 9 data points on each
line, but with a space separating them, so not something simple like a
comma. Every attmpt I've made so far to read these in results in one string
per line, rather than 9 data points per line.

Dave






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.