Mathematica 中 Manipulate[] 的自定义控制器
我创建了一个函数 test[],如果需要的话,它也可以是符号测试,并且我正在尝试在操作中实现它。 test[] 看起来像这样:
test[]:=Button["Label",Functionality[]];
如果直接在 Manipulate[] 中使用,这将返回错误,但如果它包装在 Dynamic 或 Evaluate 中,则有效。
Manipulate[content,test[]];
Manipulate::vsform:Manipulate 参数 test[] 没有变量规范的正确形式。
Manipulate[content,Dynamic[test[]]]
这个有效
Manipulate[content,Evaluate[test]]
请注意,虽然这个有效,但测试不是一个函数
Manipulate[content,Evaluate[test[]]]
这适用于我的 mac,但不适用于我工作的 PC...
我认为问题与 Manipulate 为 HoldAll 有关,但不明白为什么 Dynamic[ ] 应该解决这个问题。另外,Evaluate[] 只能在某些时候起作用。
那么,为什么需要 Dynamic[] 或 Evaluate[] 呢?查看高级操作教程的自定义控制器部分,我没有看到任何对此问题的引用,并且在其他地方找不到任何内容。
I've created a function test[], which could also be a symbol test, if need be, and I'm trying to implement it in a manipulate. test[] looks like this:
test[]:=Button["Label",Functionality[]];
This will return an error if used directly in a Manipulate[], but works if it is wrapped in a Dynamic or an Evaluate.
Manipulate[content,test[]];
Manipulate::vsform: Manipulate argument test[] does not have the correct form for a variable specification.
Manipulate[content,Dynamic[test[]]]
This one works
Manipulate[content,Evaluate[test]]
Note that while this works, test is not a function
Manipulate[content,Evaluate[test[]]]
This works on my mac, but not my PC at work...
I think the issue is something to do with Manipulate being HoldAll, but don't understand why Dynamic[] should fix this. Also, Evaluate[] will only work some of the time.
So, why is the Dynamic[] or Evaluate[] necessary? Looking under the custom controllers section of the advanced manipulate tutorial, I see no references to this issue, and could not find any elsewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以内联
Button
,而不是使用单独的test[]
函数。否则,您上一个示例,Manipulate[content,Evaluate[test[]]]
,确实在 Mathematica 8 中的我的机器上显示按钮。平台之间应该没有区别( Windows 或 Mac)。如果您正在做的事情与
Manipulate
默认提供的内容完全不同,您可能会发现使用Dynamic
从头开始构建它更方便(这是我通常所做的) 。以下是如何将一些按钮作为控制器包含在内的示例。
首先,设置要在
Manipulate
中显示的内容:然后设置
Manipulate
本身:这是一个示例,表明即使
Button
是在单独的函数中定义的,这也可以工作:正如您在问题中提到的,这里有必要将该函数包装在 <代码>评估获取内联
Button
。否则,Manipulate
将无法注意到我们这里是一个控件,而不是变量。You can inline the
Button
instead of using a separatetest[]
function. Otherwise you last example,Manipulate[content,Evaluate[test[]]]
, does show the button on my machine in Mathematica 8. There should be no difference between platforms (Windows or Mac).If you're doing something sufficiently different from what
Manipulate
provides by default, you may find it more convenient to build it from scratch usingDynamic
(this is what I usually do).Here's an example of how to include some buttons as controllers.
First, set up something to show inside the
Manipulate
:Then set up the
Manipulate
itself:Here's an example showing that this works even if the
Button
is defined in a separate function:As you mentioned in your question, here it is necessary to wrap the function in
Evaluate
to obtain an inlinedButton
. OtherwiseManipulate
will not be able to notice that what we have here is a control and not a variable.