更新时间:2023-09-06 22:19:40
Credits go to @Slayton, but you actually can do the same thing for assigning values too, using deal:
[a([a.b]==1).b]=deal(3)
那么细分:
[a.b]
检索数组a
的所有b
字段,并将其放入逗号分隔列表.
retrieves all b
fields of the array a
and puts this comma-separated-list in an array.
a([a.b]==1)
使用逻辑索引仅索引a
满足约束的元素.随后,上面的完整命令根据
uses logical indexing to index only the elements of a
that satisfy the constraint. Subsequently the full command above assigns the value 3
to all elements of the resulting comma-separated-list according to this.