How can I compare the ranks of 2 random cards from a deck in matlab

Say I have 2 cards '7D' and 'JC' 7 of diamond and jack of clubs. How do I tell matlab to compare and print a certain result when one is greater than the other and print results for when one is ranked lower?

Risposte (1)

[~, rank1] = ismember(cardname1(1:end-1), {'2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'});
[~, rank2] = ismember(cardname2(1:end-1), {'2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'});
if rank1 > rank2
disp('certain result')
elseif rank1 < rank2
disp('results')
else
cards are equal. Guess we should crash
end

2 Commenti

should I replace cardname1 and 2 with the card strings?
You should replace cardname1 with the variable that holds the card strings, since it is very unlikely that you are wanting to do this for fixed card strings.
For example
FirstCard = '7D';
SecondCard = 'JC';
[~, rank1] = ismember(FirstCard(1:end-1), {'2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'});
[~, rank2] = ismember(SecondCard(1:end-1), {'2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'});

Accedi per commentare.

Categorie

Scopri di più su Card games in Centro assistenza e File Exchange

Richiesto:

il 27 Nov 2015

Commentato:

il 27 Nov 2015

Community Treasure Hunt

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

Start Hunting!

Translated by