183k views
5 votes
) Using Average rank method (in this case each of n candidates has been given a position from 1 to n by each of the voters, the integers representing the positions are averaged to create a rank-aggregated list. If ties occur, then pick a ranking list that appears most often as the "tie-breaking list". If i, j are in a tie, but in the list we choose i is ahead of j then that is the order.)

User Andy King
by
3.4k points

1 Answer

3 votes

Answer:

See explaination

Step-by-step explanation:

% open the file to read the data of vote

file_ID = fopen('inp.txt','r');

% Split each line by comma and read data to vector

A=textscan(file_ID,'%s %s %s %s %s','Delimiter',',');

% Initialize variables to count the votes

BS=0;

TC=0;

JK=0;

HC=0;

DT=0;

% Counting first position vote got for each participant

for i=1:29

if A{1}{i}=='BS'

BS=BS+1;

elseif A{1}{i}=='TC'

TC=TC+1;

elseif A{1}{i}=='JK'

JK=JK+1;

elseif A{1}{i}=='HC'

HC=HC+1;

else

DT=DT+1;

end

end

% Assign count variable to array Vote

Vote= [BS,TC,JK,HC,DT];

% Corresponding to each array element give the name

Particpent_name = {'BS','TC','JK','HC','DT'};

% Finding maximum value of array vote

% That person is the winner

[maximum,index] = max(Vote);

str = ['Winner of election is ',Particpent_name{index}];

disp(str)

disp('Vote he got is')

disp(Vote(index))

User Sheba
by
3.3k points