Im programming a mini game and i wanted help with how to rank based on time

2 ビュー (過去 30 日間)
nty huy
nty huy 2019 年 10 月 23 日
回答済み: Katie 2019 年 10 月 24 日
i wanted to rank the player based on time say 10 second is first, 20 seconds is second and so on, what code can i use for that if anyone can help

回答 (1 件)

Katie
Katie 2019 年 10 月 24 日
Hi! If you're just storing time as number of seconds, you can use the sort function. Here's a quick example to illustrate:
times=[10, 55, 62, 12, 15];
[OrderedTimes ind]=sort(times);
%outputs are as follows:
%OrderedTimes=[10 12 15 55 62];
%ind=[1 4 5 2 3];
You could also store your times as datetime objects and do the same:
datestrings={'00:00:10','00:00:55','00:01:02','00:00:12','00:00:15'};
times1=datetime(datestrings,'InputFormat','HH:mm:ss');
[OrderedTimes1 ind1]=sort(times1);
In both cases, the "ind" variable output from the sort function will give you the indicies you need to pull out any other player info you need for the ranking (e.g., the player name of the second place winner could be found with names(ind(2)) )

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by