cell2mat not working when cells are different lengths and what to find combinations
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Shadaab Siddiqie
2020 年 12 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!