开发者

Numbering the Tables in Mathematica and Grid

I am new to Mathematica. I will try to do my best to write it effectively.

I have two questions:

Q1: I have three tables which give me values as {x1,y1,z1} ,{x2,y2,z2}...The code is given below:

    Table[Table[Table[ {xcord, ycord, zcord},  
                       {xcord, 0, 50, 5}],  
                       {ycord, 0, 50,5}],   
                       {zcord, 50, 150, 10}]  

Now I need an output like this

{1,x1,y1,z1}

{2,x2,y2,z2}

{3,x3,y3,z3}

.
.
{n,xn,yn,zn}

There are two problems with this.开发者_StackOverflow

First, I get my results formatted as something like this {x1,y1,z1},{x2,y2,z2} .... {xn,yn,zn}, but I want it formatted in this way:

 {x1,y1,z1}

 {x2,y2,z2}

 {x3,y3,z3}

 .
 .
 {xn,yn,zn}

Second, I can't number each set of elements adding the numbers in front of each set of elements like

{1,x1,y1,z1}

{2,x2,y2,z2}

{3,x3,y3,z3}

.
.
{n,xn,yn,zn}

I tried to make separate tables for each set of co-ordinates and number these corresponding to each set of the co-ordinates. Then I tried to get each of them in separate columns and join them but still I haven't been successful.

Q2: I would like to separate the values obtained from the tables above into a grid system like the one below. Something like how we all do in Excel where all values reside in a separate cells.

                 Number          X values  Y Values  Z values
                     1            x1        y1       z1
                     2            x2        y2       z2
                     .
                     .
                     n            xn        yn        zn


Perhaps this is what you are looking for.

The element numbers are added by two alternative methods, giving c and d.

a = Table[Table[Table[{xcord, ycord, zcord}, {xcord, 0, 50, 5}],
    {ycord, 0, 50, 5}], {zcord, 50, 150, 10}];
b = Flatten[a, 2];
c = MapIndexed[Flatten[{First[#2], #1}] &, b];
d = Transpose[Prepend[Transpose[b], Range[Length[b]]]];
Print[Row[{"c==d? ", c == d}]]
TableForm[Append[Take[c, 5], Table[".", {4}]],
 TableHeadings -> {None,
   {"Number", "X Values", "Y Values", "Z Values"}}]

c==d? True

Number X Values Y Values Z Values

1 0 0 50

2 5 0 50

3 10 0 50

4 15 0 50

5 20 0 50

. . . .


Perhaps:

i = 0; t2 = 
 Grid[Join[{{"Number", "X Values", "Y Values", "Z Values"}}, 
   Flatten[Table[{++i, xcord, ycord, zcord}, 
                              {xcord, 0, 50, 5}, 
                              {ycord, 0, 50, 5}, 
                              {zcord, 50, 150, 10}], 2]], 
 Frame -> All]

Numbering the Tables in Mathematica and Grid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜