假设我有一个非标量结构。
现在我想要将
以下两种方法都无法实现:
有其他想法吗?
res = struct(); res(1).name = 'hello'; res(2).name = 'world';
现在我想要将
name
字段的所有内容复制到另一个字段,比如说tag
。以下两种方法都无法实现:
>> res.tag = res.name;
Scalar structure required for this assignment.
>> [res.tag] = [res.name];
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
>> {res.tag} = {res.name};
{res.tag} = {res.name};
↑
Error: The expression to the left of the equals sign is not a valid target for an assignment.
有其他想法吗?
[res.tag] = res.name;
。我们在左边有一个数组,在右边有一个序列。 - Dimsdeal
函数后不久开发的简化语法。以前是[res.tag] = deal(res.name)
,后来他们意识到如果可以省略deal
调用并直接执行赋值操作,则不会存在歧义。 - Cris Luengodeal
的一点内容。 - Luis Mendo[res.test] = 10,20
不起作用,我最近回答另一个问题时也注意到了这一点。我认为这是因为逗号分隔语句,所以它是[res.test] = 10
作为一个语句,而20
则是另一个语句。好的回答! - Cris Luengo