Mathematica 中的嵌套操作
请考虑:
Function[subID,
pointSO[subID] = RandomInteger[{1, 4}, {5, 2}]] /@ {"subA", "subB"};
Manipulate[
Manipulate[
Graphics[{
Black, Rectangle[{0, 0}, {5, 5}],
White,Point@pointSO[subID][[i]]
},
ImageSize -> {400, 300}],
{i,Range[Length@pointSO[subID]]}],
{subID, {"subA", "subB"}}]
假设 pointSO[subID]
实际上产生不同的列表长度,有没有办法避免 2 Manipulate
考虑到其中一个被操纵变量依赖于另一个?
Please consider:
Function[subID,
pointSO[subID] = RandomInteger[{1, 4}, {5, 2}]] /@ {"subA", "subB"};
Manipulate[
Manipulate[
Graphics[{
Black, Rectangle[{0, 0}, {5, 5}],
White,Point@pointSO[subID][[i]]
},
ImageSize -> {400, 300}],
{i,Range[Length@pointSO[subID]]}],
{subID, {"subA", "subB"}}]
Provided that pointSO[subID]
actually yields to lists of different length, is there a way to avoid having 2 Manipulate
given that one of the manipulated variable depends on the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否完全得到了您所要求的内容,但我认为您想要的是如下内容:
给定一个带有一个变量的 UI,比如说一个可以改变大小的数组,并且另一个(因)变量,它表示当前数组的索引,您希望从 UI 中使用该索引来索引数组。
但是您不想修复 UI 中的索引变量布局,因为它在运行时取决于数组的大小,而数组的大小可以使用第二个变量进行更改。
这是一个单操作,它有一个带有索引控制变量的 UI,该变量随着数组大小的变化而在 UI 上动态更新。
我使用 SetterBar 作为索引(因变量),但您也可以使用滑块。 SetterBar 在 UI 上更清楚地显示了正在发生的变化。
当您更改数组的长度时,索引控制变量会自动更新其允许的最大索引,以匹配数组的当前长度。
当缩小数组时,索引也会缩小。
我不确定这是否是您想要的,但如果是,您可以调整此方法以适应您的问题
晚上 8:30 更新
仅供参考,刚刚修复了上面的代码以添加所需的额外逻辑。
I am not sure that I got exactly what you are asking for, but I figured what you want is something like the following:
Given a UI with one variable, say an array that can change in size, and another (dependent) variable, which represents say an index into the current array that you want to use from the UI to index into the array.
But you do not want to fix the index variable layout in the UI, since it depends, at run time, on the size of the array, which can change using the second variable.
Here is a one manipulate, which has a UI that has an index control variable, which updates dynamically on the UI as the size of the array changes.
I used SetterBar for the index (the dependent variable) but you can use slider just as well. SetterBar made it more clear on the UI what is changing.
When you change the length of the array, the index control variable automatically updates its maximum allowed index to be used to match the current length of the array.
When you shrink the array, the index will also shrink.
I am not sure if this is what you want, but if it, you can adjust this approach to fit into your problem
update 8:30 PM
fyi, just made a fix to the code above to add a needed extra logic.
为了避免切换列表时出现
i
太大的问题,可以在Manipulate
的开头添加一个If[]
语句,例如也许更好的办法是在列表之间切换时重置
i
。这可以通过做类似的事情来完成To avoid the problem of
i
being too large when switching lists, you could add anIf[]
statement at the beginning of theManipulate
, e.g.Maybe nicer is to reset
i
when switching between lists. This can be done by doing something like保留每个数据集的选择设置的替代实现:
输出示例:
An alternative implementation that preserves selection settings for each data set:
Output examples: