cell2mat not working when cells are different lengths and what to find combinations
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to obtain a matrix with all the player Vs player combinations. Whe i have my players names A, B, C and D the code below works perfectly. However whe i give my players names such as Alice, Ben, Cody and David the following code does not work. Is there something i can add to make it work?
function[changes] = calculating_changes(rating,position)
changes = containers.Map;
for player = keys(rating)
changes(player{1}) = 0;
end
all_players=cell2mat(keys(rating))
%cell2mat converts the cell array to an ordinary array
%puts the changes in a list with their corresponding player
match_table = nchoosek(all_players,2)
%nchoosek is used to get a marix with all player vs player combinations
end
This code the output as followed when using ABCD I'd like it to do the same but with names not letters
all_players =
'ABCD'
match_table =
6×2 char array
'AB'
'AC'
'AD'
'BC'
'BD'
'CD'
0 commentaires
Réponses (1)
Shadaab Siddiqie
le 9 Déc 2020
Form my understanding you want to obtain a matrix with all the player Vs player combinations. But since player name might not be of same lenght, you can create a player Vs player cell array. This can be done by removing
all_players=cell2mat(keys(rating))
and replacing
match_table = nchoosek(all_players,2)
with
match_table = nchoosek(keys(rating),2)
0 commentaires
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!