我不确定你想做什么。我已经制定了一些与您的预期相关的代码:
val = 101:105;
strct_template.index = 1;
strct_template.b = 1;
strct_array = repmat(strct_template,length(val),1);
for i=1:length(val)
strct_array(i).index = i;
strct_array(i).b = val(i);
end
subs = [1; 2; 4; 2; 4];
sum_example = accumarray(subs, vertcat(strct_array.b)) % example from accumarray in matlab help
mult_example = accumarray(subs, vertcat(strct_array.b),[],@prod)
subs = ones(length(strct_array),1);
mult_example2 = accumarray(subs, vertcat(strct_array.b),[],@prod) % I suppose you wanted this
mult_example3 = prod(vertcat(strct_array.b)) % which gives the same result as this
这是我第一次使用 accumarray 函数,所以也许我误解了您的需要。希望能帮上忙