Creating a leaderboard and scoring system
3 views (last 30 days)
Show older comments
Hello and sorry if my question might sound hard to understand at first!
Me and some coursemates went flying on a uni simulator which gave us different parameters under the form of arrays ( for example, altitude, time etc)
We had to create a program that takes those parameters, plots them into graphs and determines who was the best pilot.
I thought about using a scoring system similar to the ones in games, where at the end of each evaluation the data will be sorted in a hierarchical way.
For example taking the Altitude/Time graph, I had to determine the area underneath that graph, which I found out using the trapz function, afterwards I sorted ascending all that data, and the pilot with the smallest area is declared the winner of that round. All fun and games until here... -ish.
We were 6 pilots, therefore place 1 received 5 points, place 2 received 4 points etc place 6 received 0 points. I want that each pilot to receive a variable ( For example, lets call a pilot John) that is equal to 0 at the beginning. If john won 3rd place, he has to receive therefore 3 points. I dont know how to create this, as all I did was just compute that area and sort it. I dont know how to assign each pilot that area and how to give him those points.
Here is some of my coding:
plot(time_1,alt_1,'r');
plot(time_2,alt_2,'b');
plot(time_3,alt_3,'g');
plot(time_4,alt_4,'y');
plot(time_5,alt_5,'k');
plot(time_6,alt_6,'m');
title('Altitude variation over time');
xlabel('Time(s)');
ylabel('Altitude(m)');
legend('Andrei','Mauro','John','Khalid','Melbin','Sully')
hold off;
area1=trapz(time_1,alt_1);
area2=trapz(time_2,alt_2);
area3=trapz(time_3,alt_3);
area4=trapz(time_4,alt_4);
area5=trapz(time_5,alt_5);
area6=trapz(time_6,alt_6);
area_array=[area1,area2,area3,area4,area5,area6];
area_sorted=sort(area_array,'ascend');
area_sorted;
Help would be much appreciated!
0 Comments
Answers (1)
Derek Michaelis
on 31 Jan 2020
If you ever have trouble with sorting listed items on matlab, I put a more universal guide down below this one! It's much shorter.
Although it is probably way to late to help you, I see there are some people still veiwing this question. It may seem like a lot of code to do this small task but the majority was just copy and past, or just using the replace tool (in ctrl f) a few times after typing a couple lines. Either way, if you have a lot more in a list than just 6 that you need to sort out, then I would definatly recomend this over brute forcing it.
% in this section I just mached the people up with their area under the curve
Andrei = area_array(1);
Mauro = area_array(2);
John = area_array(3);
Khalid = area_array(4);
Melbin = area_array(5);
Sully = area_array(6);
% I used a for loop so it would cycle through all the peoples placings and give me a changing variable to work with
for k=1:1:6
% if you didn't understand why I was setting there names to equal the values earlier it was so that after it was
% sorted we have a way to cancel out there original values leting us know if it matches a sorted value
if area_sorted(k)/Andrei==1
AndreiScore=AndreiScore+6-k; %here is where I calculated their points they got making it so you could add it to priviously gotten points
fprintf('\nAndrei is number %i and has a score of %i points\n',k,AndreiScore)
elseif area_sorted(k)/Mauro==1 %the rest of this I just copied and pasted and replaced the names
MauroScore=MauroScore+6-k;
fprintf('\nMauro is number %i and has a score of %i points\n',k,MauroScore)
elseif area_sorted(k)/John==1
JohnScore=JohnScore+6-k;
fprintf('\nJohn is number %i and has a score of %i points\n',k,JohnScore)
elseif area_sorted(k)/Khalid==1
KhalidScore=KhalidScore+6-k;
fprintf('\nKhalid is number %i and has a score of %i points\n',k,KhalidScore)
elseif area_sorted(k)/Melbin==1
MelbinScore=MelbinScore+6-k;
fprintf('\nMelbin is number %i and has a score of %i points\n',k,MelbinScore)
else
SullyScore=SullyScore+6-k;
fprintf('\nSully is number %i and has a score of %i points\n',k,SullyScore)
end
end
Also, for others who are having similar problems, and you just want to put them in order in a list on matlab and that is it, then it can be a bit shorter...
NameA = List_Of_Numbers_Before_Sorting(1)
NameB = List_Of_Numbers_Before_Sorting(2)
Name... = List_Of_Numbers_Before_Sorting(...)
...
Sorted_List = sort(List_Of_Numbers_Before_Sorting) %if you want it to decend instead it sould still work
for k = 1 : 1 : Number_Of_People_On_The_List
if Sorted_List(k) / NameA == 1
fprintf('NameA, ')
elseif Sorted_List(k) / NameB == 1
fprintf('NameB, ')
elseif Sorted_List(k) / Name... == 1
fprintf('Name..., ')
...
else
fprintf('Name...')
end
end
This will give you a list of the words in the right order and the only thing separaiting them will be commas and spaces, if you want every word on a new line just inclued "\n" instead of the ", " in the fprintf lines.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!