对 Mathematica 和 Grid 中的表格进行编号

发布于 2024-12-02 02:21:23 字数 1209 浏览 4 评论 0原文

我是 Mathematica 的新手。我会尽力写得有效。

我有两个问题:

Q1: 我有三个表,它们给我的值为 {x1,y1,z1} ,{x2,y2,z2} ...代码如下:

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

现在我需要这样的输出

{1,x1,y1,z1}

{2,x2,y2,z2}

{3,x3,y3,z3}

.
.
{n,xn,yn,zn}

这有两个问题。

首先,我得到的结果格式类似于 {x1,y1,z1},{x2,y2,z2} .... {xn,yn,zn},但我希望它的格式如下:

 {x1,y1,z1}

 {x2,y2,z2}

 {x3,y3,z3}

 .
 .
 {xn,yn,zn}

其次,我无法对每组元素进行编号,在每组元素前面添加数字,就像

{1,x1,y1,z1}

{2,x2,y2,z2}

{3,x3,y3,z3}

.
.
{n,xn,yn,zn}

我尝试为每组坐标制作单独的表格,并对与每组坐标相对应的这些进行编号。然后我尝试将它们放在单独的列中并将它们连接起来,但仍然没有成功。

第二季度: 我想将从上表中获得的值分离到如下所示的网格系统中。就像我们在 Excel 中所做的那样,所有值都驻留在单独的单元格中。

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢蛋碎的人ぎ生 2024-12-09 02:21:23

也许这就是您正在寻找的。

元素编号通过两种替代方法相加,给出 c 和 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?真

数 X 值 Y 值 Z 值

1 0 0 50

2 5 0 50

3 10 0 50

4 15 0 50

5 20 0 50

。 。 。 。

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

. . . .

奶茶白久 2024-12-09 02:21:23

也许:

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]

在此处输入图像描述

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]

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文