Matlab:如何合并结构数组字段的值



是否可以轻松地将结构数组字段中的值组合到一个数组中,而无需循环遍历数组中的每个单独结构?

如需参考,请参阅所附代码:

% build random struct array with only one field
% for demonstration only
clear i s out;
for i = 1:10
    s(i).value = rand;
end
s
% not working, as it returns multiple results
s(1:end).value
% combine all "value" into a single array using for-loop
out = zeros(length(s), 1);
for i = 1:length(s)
    out(i) = s(i).value;
end
out

简单地说,目标是"合并"所有"值"字段。

您可以使用以下方法获得它:

out = [s.value]

CCD_ 1返回所有值,CCD_。

最新更新