How to use special characters in MATLAB (unicode playing cards)?
13 views (last 30 days)
Show older comments
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 Comments
Answers (2)
David Hill
on 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 Comments
Walter Roberson
on 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.
Walter Roberson
on 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 Comment
Walter Roberson
on 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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!