How to use special characters in MATLAB (unicode playing cards)?

13 visualizzazioni (ultimi 30 giorni)
Hello,
I am new to MATLAB and I am making a blackjack game for a project, and for this I would like to use Unicode playing card symbols within MATLAB, however the error is coming up with:
Error: File: untitled2 Line: 1 Column: 12
Invalid text character. Check for unsupported symbol, invisible character, or
pasting of non-ASCII characters.
I am using the playing card unicode symbols from the following website (only the cards which are used in blackjack 2-10 and AJKQ): https://en.wikipedia.org/wiki/Playing_cards_in_Unicode
Can someone please explain to me how to put it into MATLAB? I have looked through the website for someone with a similar issue/solution but I could not find one.
If it is necessary I will upload my function file.
Thank you.
  3 Commenti
Aditya Sajeesh
Aditya Sajeesh il 26 Apr 2022
Hello Stephen, thank you for your reply, I have attached my code above, in essence what I am trying to do is test that when the function receives two vector inputs, playerCards and dealerCards (which will be randomly generated in my full program but for this function it is just predetermined values) and outputs dispplayerCards and dispdealerCards respectively, which contain Unicode playing cards for each value within playerCards and dealerCards.
I have not completed the function yet (it won't run properly) because most of my focus has been on trying to get the Unicode cards to work. If I am not able to use these cards then I might just have to try and use what David Hill suggested as the answer or I can just randomly select a suit from char(9824:9831) and append it to the front of a number to make a "card".
Walter Roberson
Walter Roberson il 26 Apr 2022
you do not appear to have quoted any of the characters.

Accedi per commentare.

Risposte (2)

David Hill
David Hill il 25 Apr 2022
I believe the only unicode support for card symbols is:
char(9824:9831)
You can build your own cards via images. Here is an example of my blackjack game:
  2 Commenti
Aditya Sajeesh
Aditya Sajeesh il 26 Apr 2022
Hello David, thank you for your answer.
I have not studied or learned the GUI of MATLAB, is this the only way to show PNG card files in MATLAB or is there another way? If not then I think I will just append a random element from char(9824:9831) to the front of a number to make a simplified "card" which includes a suit.
Walter Roberson
Walter Roberson il 26 Apr 2022
You can imread() images -- probably into cell arrays. You would then have an axes(), and you would image() the appropriate cell array content. You would probably want to use the optional XData and YData parameters to image(), in order to position the image into the axes, which is the way that you handle multiple images in the same axes.

Accedi per commentare.


Walter Roberson
Walter Roberson il 26 Apr 2022
This is closer...
function [ asciioutput ] = asciiCardsFunction(playerCards, dealerCards)
V1 = {'🂡' '🂱' '🃁' '🃑'};
V2 = {'🂢' '🂲' '🃂' '🃒'};
V3 = {'🂣' '🂳' '🃃' '🃓'};
V4 = {'🂤' '🂴' '🃄' '🃔'};
V5 = {'🂥' '🂵' '🃅' '🃕'};
V6 = {'🂦' '🂶' '🃆' '🃖'};
V7 = {'🂧' '🂷' '🃇' '🃗'};
V8 = {'🂨' '🂸' '🃈' '🃘'};
V9 = {'🂩' '🂹' '🃉' '🃙'};
V10 = {'🂪' '🂺' '🃊' '🃚'};
%V11 = {'🂫' '🃋'};
%V12 = {'🂭' '🃍'};
%V13 = {'🂮' '🃎'};
cardVal2 = [V1, V2, V3, V4, V5, V6, V7, V8, V9, V10];
% this set of vectors stores all possible ASCII values for all card symbols
% within blackjack
dispplayerCards = [];
dispdealerCards = [];
for i = 1:numel(playerCards)
dispplayerCards{i} = cardVal2{playerCards(i)};
end
for i = 1:numel(dealerCards)
dispdealerCards{i} = cardVal2{dealerCards(i)};
end
asciioutput = [dispplayerCards{:};dispdealerCards{:}];
end
  1 Commento
Walter Roberson
Walter Roberson il 26 Apr 2022
In practice it does not work because each of those card faces is stored as a pair of characters, and when you put those together into the character array for display to the command line, MATLAB does not have the ability to treat them as proper characters for display purposes.

Accedi per commentare.

Categorie

Scopri di più su Just for fun in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by