更新时间:2022-11-29 14:53:04
w=[7 2 6];
votes = ['A' 'B' 'B'
'C' 'A' 'A'
'D' 'B' 'A'
'A' 'A' 'C'];
options = ['A', 'B', 'C', 'D']';
%'//Make a cube of the options that is number of options by m by n
OPTIONS = repmat(options, [1, size(w, 2), size(votes, 1)]);
%//Compare the votes (streched to make surface) against a uniforma surface of each option
B = bsxfun(@eq, permute(votes, [3 2 1]) ,OPTIONS);
%//Find a weighted sum
W = squeeze(sum(bsxfun(@times, repmat(w, size(options, 1), 1), B), 2))'
%'//Find the options with the highest weighted sum
[xx, i] = max(W, [], 2);
options(i)
结果:
B
A
D
A