【问题标题】:How do I index list elements in For loop in Mathematica?如何在 Mathematica 的 For 循环中索引列表元素?
【发布时间】:2018-09-04 10:47:37
【问题描述】:

我不知道在 Mathematica 中按以下代码的意图打印出多个 3D 图所需的语法。

For[i = 1, i <= accBeta + 1, i++,
    ListPlot3D[p3[[All, i]], PlotRange -> All, ColorFunction -> "Rainbow"]
]

这里 p3 是包含信息的列表列表,而 i 是我的计数索引。这不会出错,但输入会被忽略。你能帮我解决这个问题吗?

菲利克斯

【问题讨论】:

    标签: for-loop syntax wolfram-mathematica notation


    【解决方案1】:

    一些示例数据

    p3 = Table[Sin[k j^2 + i], {i, 0, Pi, Pi/5}, {j, 0, Pi, Pi/5}, {k, 3}];
    

    以下是等价的

    Table[ListPlot3D[p3[[x]], Mesh -> None, InterpolationOrder -> 0,
      ColorFunction -> "Rainbow"], {x, Length[p3]}]
    
    Map[ListPlot3D[#, Mesh -> None, InterpolationOrder -> 0,
       ColorFunction -> "Rainbow"] &, p3]
    

    【讨论】:

      【解决方案2】:

      这里实际上不需要For 循环。例如你可以使用Table:

      Table[ListPlot3D[p3[[All,i]]], {i, 1, accBeta+1}]
      

      这应该打印你的情节。希望对您有所帮助。

      Mathematica Stack Exchange 上有很多相关问题 - 通常答案是不要使用 ForDo 循环 :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-18
        • 2021-12-01
        • 1970-01-01
        • 2021-05-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多