Assigning a value to certain indexed elements of a struc variable
1 次查看(过去 30 天)
显示 更早的评论
I am trying to assign a certain value to several elements of an indexed structure:
indices = 1:3
people(indices).gender ='m'
..but get the error
"Expected one output from a curly brace or dot indexing expression, but there were 3 results."
Is this a limitation of how Matlab can work with structures, or am I making a mistake in how I am using these variables?
Is this the (still not implemented) enhancement described in this other thread reporting the same error?
Thanks for any help! I am using 2016b.
0 个评论
采纳的回答
Walter Roberson
2018-3-11
[people(indices).gender] = 'm';
6 个评论
Walter Roberson
2018-3-12
Note that Jos's solution only works for the initial creation of the output, not for setting a field within an existing structure
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!