如何在Matlab中的大型结构数组中同时设置字段?

时间:2013-05-23 22:43:16

标签: arrays matlab structure

我有一个大型结构阵列。

我想对处理此数组的函数执行灵敏度分析。

所以,假设我的结构数组有名字's',10,000个元素,字段名'x'和'y'。

我想做以下事情:

xs = [s(:).x];
xs = xs + 5*randn(size(xs));
s(:).x = xs;

可悲的是,最后一步是无效的matlab。有什么想法吗?希望避免循环。

1 个答案:

答案 0 :(得分:0)

From this answer并在玩完交易之后。我想我有你想要的东西,但它需要使用num2cell将xs转换为单元格数组:

xs_cell = num2cell(xs); % convert matrix to cell array.
[S(:).X]=xs_cell{:}; % update the values in the field X