www.pudn.com > snippets(1).rar > majority_vote.m, change:2009-10-12,size:636b


function [res_seq,allvotes] = majority_vote(res,nfr)

len = length(res);
len_seq = len/nfr;
if mod(len_seq,1)~=0
  len
  nfr
  res_seq = res;
  error('error in MAJORITY_VOTE: total frame number must be a multiple of individual sequence frame number!');
end

mxcls = max(res);
res_seq = zeros(len_seq,1);
allvotes = zeros(len_seq,mxcls);

st = 1;
ed = nfr;

for u = 1:len_seq

  % count votes for each class
  votes = zeros(mxcls,1);
  for v = 1:mxcls
    votes(v) = nnz(res(st:ed)==v);
  end
  allvotes(u,:) = votes';

  % find class with most votes
  [mx,res_seq(u)] = max(votes);

  % next sequence
  st = st+nfr;
  ed = ed+nfr;

end