function v=m_weighted_majority(th,w_vec)
% M_WEIGHTED_MAJORITY computes from the threshold th and
% the weights w_vec a weighted majority game. Converts
% a logical array v into double to be useable within
% a running Mathematica session using MATLink.
%
% http://matlink.org/  
% 
% Example: 
% From a running Mathematica session define the
% weights vector and the threshold to pass a bill
% for instance as
% mwghs={64,193,63,311} and 
% mth=316
% 
% Then define 
% mwmg = MFunction["m_weighted_majority"];
%
% and compute the weighted majority game through
% wg=mwmg[mth,mwghs]
%
% Under Matlab 
% Usage: v=m_weighted_majority(th,w_vec)
% Define variables:
%  output:
%  v        -- A weighted majority game.
%  input:
%  th       -- Threshold to pass a bill (positive number).
%  w_vec    -- Vector of weights.


%  Author:        Holger I. Meinhardt (hme)
%  E-Mail:        Holger.Meinhardt@wiwi.uni-karlsruhe.de
%  Institution:   University of Karlsruhe (KIT)  
%
%  Record of revisions:
%   Date              Version         Programmer
%   ====================================================
%   10/18/2013        0.5             hme
%                



n=length(w_vec);
sumw=w_vec(1); for ii=2:n, sumw=[sumw w_vec(ii) sumw+w_vec(ii)]; end
v=sumw>=th;
v=double(v);
