MathGroup Archive 1999

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

Search the Archive

Re: Reading data.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21180] Re: [mg21076] Reading data.
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Fri, 17 Dec 1999 01:23:23 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Madhusudan Singh [chhabra at eecs.umich.edu] wrote:

> I have a data file with 7 columns and 100 rows. How do I import data from
> that into 7 different arrays in Mathematica ? The data is in exponential
> form and is tab separated. Top few rows are shown at the end of this
> posting.
>
> <Snip>
>
> Second question : how do I do a linear fit of of one column as x and
> another as y ?
>
> What is the format of such an output ?

First, you'd do yourself a great favor if you put your data in ordinary
numerical form first, before getting them into Mathematica. This you can do
in Excel or whatever you are using to produce them, using
Format|Cells|Number|Number and giving as many figures as necessary to have
the precision you desire. Then save your file as tab delimited text, which
you may call for example mg.txt. Then read your data into Mathematica:

In[1]:=
inp = ReadList[
    "c:\mg.txt", {Number, Number, Number, Number, Number, Number,
      Number}];

Your seven columns are then given by

In[2]:=
cols = Transpose[inp];

Suppose now you want to do a linear fit of, say, column 2 against column 1:

In[3]:=
d12 = Transpose[{cols[[1]], cols[[2]]}];

In[4]:=
un[x_]:=Fit[d12, {1, x}, x]

un[x]= -8.71562*10^-7 + 1.24662 x

(I took your data as they come in your message, with only 17 rows, after
deleting the first row of three elements). Linear fit looks more or less
right, as you may see by yourself, but that's not for me to judge. At least
there is good agreement in the two or three first significant figures. Take
a look at

In[72]:=
{un[#[[1]]], #[[1]]} & /@ d12

Tomas Garza
Mexico City



  • Prev by Date: Dropping terms in a complex expression
  • Next by Date: Re: Mathematica and Topology.
  • Previous by thread: Re: Reading data.
  • Next by thread: Re: Reading data.