Reading greek letters!
Afficher commentaires plus anciens
I need to read text from an EXCEL file that will include greek letters in some cells. While I can transform the letters (e.g., spelling out "alpha" in place of the actual letter), I need to preserve the content. Currently, when I read the file using readcell, I get the greek letters in the text, but as soon as I try to do anything with them they get substituted with question marks. This is problematic, as I need to make decisions based on the text, and can't do that if every theta, eta, and nu is just going to become identical ?'s.
So, any ideas?
EDIT: For clarification on "...but as soon as I try to do anything..."
Below, the word tau, by itself, is the greek letter itself
%%%%%%%%%%%%%%%%%%%%%%
>>Text = readcell(File,'Sheet',Sheet);
>>VN = char(Text(2,1));
VN =
tau
>>switch VN
case tau
A = 'tau';
otherwise
A = 'ERROR';
end
>>A
A =
'ERROR';
%%%%%%%%%%%%%%%%%%%%%%%
Please note that when I call VN, I see the letter tau on the screen. When I save it in an .mat file and reopen, VN = '?'.
In essense, I need a way to do the reverse of what char(945) would do - where char(945) takes a MATLAB-manipulatable value and produces a greek letter, I need something that will take a greek letter and produce a MATLAB manipulative value (like Unicode or '\alpha').
5 commentaires
Adam Danz
le 20 Nov 2019
"..but as soon as I try to do anything...
???
Adam Danz
le 20 Nov 2019
If you're just referencing single greek letters, you could use the ASCII values for those characters.
For example, the ASCII value for tau is
value = double('τ') % 964, lower case
value = double(upper('τ')) % 932, upper case
So when you read in the letters, you can instantly convert them to their ASCII values.
VN = double(Text{2,1});
and then in your switch statement,
switch VN
case [932, 964] % for upper and lower cases
% code
otherwise
error()
end
I'm writing this as a comment rather than an answer because I'm unsure of how you're actually using the text and the switch case.
Jeremy Hughes
le 20 Nov 2019
To be pedantic, ASCII is only the [0 127] range of characters. Beyond 127, everything is "extended ascii" which means nothing by itself. You need to know what encoding the characters are in. <end pendantry>
In this case, the TAU character is the UTF-16 representation (which is how MATLAB stores characters). The "?" showing up in display can mean one of two things:
The character isn't recognized from the encoding it's stored in the file as, or the FONT you're using doesn't have the character available.
To tell which, use double(TAU_CHAR) should show you the UTF-16 value(s) for the character:
If it's
ans = 26, then MATLAB has replaced the character, as it didn't know what to do with it. Otherwise, if it there's a number other than 26, the data is there, but the FONT doesn't have an entry for that UTF-16 character.
Stephen Hall
le 20 Nov 2019
Adam Danz
le 20 Nov 2019
@Stephen Hall, I'll copy an improved version of my comment to the answers section so your question appears as answered.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!