Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Export a vector

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108829] Re: Export a vector
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 2 Apr 2010 05:20:42 -0500 (EST)

On 4/1/10 at 6:00 AM, sagittarius5962 at gmail.com (nt) wrote:

>I have a question on how to export an array from a loop with
>several iterating varibles: for example:

>equation= some equation!
>t0=1;ds1=1
>Do[{t[i]=i*t0};{eq[i]=equation/.t->t[i]};{s1[j]=j*ds1};bet[i,j]=
>r/.FindRoot[eq[i]==0,{s,s1[j]}];betn[i]=Min[bet[i,j]],{i,1,5},{j,1,5}]

>I can give the loop a name like L=Do[....] and write
>Export["file.xls",L] but what I get is the matrix with dimensions of
>i*j.

If you actually tried to Export as you described above and got
what you stated it would be very surprising. The return value
from Do is Null unless a specific Return is used per the
documentation. Setting L = Do[...] and getting what you report
would be a bug.

>can I only export bet[i] which is a vector within the loop to a
>file?

The first thing you need to realize is bet[i] is not a vector
within the loop. None of your code creates a vector or a matrix
(more properly in Mathematica a list).

The notation bet[i] is the function evaluated with the value i.
And since your code does not define values for bet with single
arguments, bet[i] will return unevaluated.

For example, I can define values for f[i,j] as follows:

In[16]:= Table[f[i, j] = RandomInteger[100], {i, 3}, {j, 3}]

Out[16]= {{35, 5, 19}, {22, 87, 75}, {98, 27, 46}}

and to demonstrate f has been assigned values for specific i,j

In[17]:= f[1, 1]

Out[17]= 35

but note,

In[18]:= f[1]

Out[18]= f[1]

since f has not be defined for a single argument. For something
that behaves like a matrix, I would do:

In[19]:= g = Table[RandomInteger[100], {3}, {3}]

Out[19]= {{70, 1, 89}, {17, 92, 49}, {43, 24, 72}}

Now I can extract the first row by:

In[20]:= g[[1]]

Out[20]= {70,1,89}

or the first column by:

In[21]:= g[[All, 1]]

Out[21]= {70,17,43}



  • Prev by Date: Re: scaling a plot via imagesize
  • Next by Date: Re: Find the solution of a system of two nonlinear, complicated equations
  • Previous by thread: Export a vector
  • Next by thread: Re: Calling kernel.dll from Mathematica